Tagged Questions
4
votes
3answers
180 views
How can I delete a trailing newline in bash?
I'm looking for something that behaves like Perl's chomp. I'm looking for a command that simply prints its input, minus the last character if it's a newline:
$ printf "one\ntwo\n" | ...
4
votes
5answers
178 views
Replace new line + 4x space to new line in stdout
I need join 2 lines into one in stdout - replace new line AND 4x space with one space but new line without space don't touch
tcpdump -vvv ... -l | xyz
this is output:
2014-06-06 AAA
BBB
...
6
votes
3answers
65 views
Print a multiline variable in a column
I have a script that collects values from a cluster. The values, in some cases, have multiple lines. I have a printf format that specifies how the data should be positioned however, it doesn't take ...
2
votes
2answers
144 views
How to parse multiple string patterns in linux shell script
I am new to linux shell and I had a hard time thinking of the solution to this. Can somebody help how to parse multiple strings (data) in a file? For below file, I want to parse all the values next to ...
-1
votes
3answers
62 views
Checking if line in file exist
I have a bash script which asks a user for the number of CPU cores and saves it to variable named $cores.
Now I want to add this variable to .bashrc, so I ask user how much CPU cores he has and then ...
38
votes
6answers
38k views
How to add a newline to the end of a file?
Using version control systems I get annoyed at the noise when the diff says No newline at end of file.
So I was wondering: How to add a newline at the end of a file to get rid off those messages?
0
votes
2answers
81 views
How to get the value from rows and columns from text file in bash?
I am working on a bash project. I need to get all the values (one at a time because I will be using them somewhere else) from a text file. The text file I will be getting is structured like this:
...
0
votes
7answers
82 views
Extract the number of failures from a test report
How would I parse following output of lein test
$ lein test
lein test nepleaks-engine.core-test
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
Where I want is get number before ...
5
votes
3answers
213 views
How to have command history with timestamps output to the terminal continuously?
I use a simple alias to enable the "tracking" of commands in one or many terminal window(s):
alias trackmi='export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"'
Then I just tail -f my .bash_history ...
6
votes
4answers
172 views
remove lines that is newer than the given date in a file
I'm stuck on how I can go about deleting lines that are newer than given date.
Here is a snippet of contents of a file.
buildsave.txt
647919 2013/11/30
647946 2013/11/30
647955 2013/12/01
648266 ...
2
votes
1answer
86 views
How to replace a leading zero with white space in SED?
Trying to find how to replace a leading zero with white space in SED. Attempting to get day of month and replace with space to filter some data that I am screen scraping.
The code I have is as ...
4
votes
6answers
228 views
Extract lines based on words on position, not column
I have a file like this:
v
ATOM 57 O LYS A 7 2.254 25.484 18.942 1.00 14.46
ATOM 77 NH1AARG A 8 5.557 19.204 13.388 0.55 24.50
TER 1648 ...
1
vote
1answer
268 views
Finding all files containing a word and then counting the number of lines
I need to recursively find all files that contain a specific word and if the word exists in file I need to find out the number of lines in that file. I have been trying to use grep but I have been not ...
0
votes
1answer
37 views
skip line that doesn't contain perticular character eg .colon
I am reading lines from the file in while loop.
while read line
do
#process line
done
I want to skip the line that does not contain colon.
Any help?
7
votes
5answers
383 views
List out strings which are substrings of other strings in the list
I have a list of names like so:
dog_bone
dog_collar
dragon
cool_dragon
lion
lion_trainer
dog
I need to extract out names that appear in other names like so:
dragon
lion
dog
I looked through the ...
33
votes
8answers
41k views
Looping through files with spaces in the names?
I wrote the following script to diff the outputs of two directores with all the same files in them as such:
#!/bin/bash
for file in `find . -name "*.csv"`
do
echo "file = $file";
diff ...
2
votes
2answers
67 views
Sed? Stripping all formatting, i.e line breaks and whitespaces, from a report text file, while masking out certain pieces
I am working on a project in which I need to remove all formatting from a text file including whitespaces and line breaks, then replace any colons with pipes. I've made some headway but I cannot find ...
1
vote
3answers
218 views
Couting all characters by BASH character class
I need to efficiently count every character of an arbitrary file by its character CLASS (as defined by the BASH man page); i.e.
[[:alnum:]], [[:alpha:]], [[:ascii:]], [[:blank:]], [[:cntrl:]], ...
0
votes
0answers
61 views
Editing metadata with bash
I have a bunch of photos(jpeg, bmp, png) that I have arranged in such a manner that the metadata is in html form in a separate file.
I would like create some script to read this html file and edit ...
1
vote
2answers
111 views
Remove just one word before pattern match in shell script
Input:
int foo(int a, void * b, int c);
Output:
int foo(int, void *, int);
Want to use "," as pattern to match. If "," pattern is matched then remove the previous word i.e. a, b & c.
2
votes
3answers
427 views
Replacing the values in one file with the values in another file in bash
I am having a csv file naming List.csv in following format:
Location,IP Address,Host Name,Domain,Domain Name, User Name,Manufacturer,Model,System Type, Serial Number, Operating System,RAM ...
7
votes
5answers
324 views
SED : Case Match Pattern Replacement
I have a source code spread across several files.
It has a pattern abcdef which I need to replace with pqrstuvxyz.
The pattern could be Abcdef (Sentence Case) then it needs to be replaced with ...
4
votes
3answers
136 views
Make a directory for each row within the given text file?
I'm trying to write a bash shell script that will read the data from a given (as an argument) file, and for each row in the file, make a sub-directory under the given (as an argument) directory.
The ...
1
vote
2answers
567 views
Editing a Java properties file with Bash
I have the following Java properties file that is maintained by humans.
# file.input = /very/old/name
# file.input = /old/name
file.input = /current/name
file.input.default = /default/name
...
1
vote
2answers
120 views
Bash: split list of files into different files?
I have several files in a directory like:
data1.dat
data2.dat
....
data24678.dat
To run another code, I need to have a text file with the names of the files but I need to split in 50 files per ...
1
vote
3answers
136 views
How can I delete the first dot before the first number?
How to remove the first dot before the first number?
For example
I have the following file
more file
Version …………2.465.76.8.332
I want to get only the version number - 2.465768.332
4
votes
2answers
135 views
How can I delete all unordered lines from a text file?
Overview
Consider an ordered list interspersed with unordered elements, e.g.:
Alligator
Ant
Falcon <--
Baboon
Badger
Armadillo <--
Caiman
Cat
How can this list be processed so that all ...
2
votes
2answers
1k views
Convert csv to HTML table
I have a Medical.csv file with rows of following format,
field: 'participation.type', displayName: 'program_type', type: 'String',path:'participation'
field: 'participation.program', ...
5
votes
4answers
4k views
Is it possible in bash, to start reading a file from an arbitary byte count offset?
I want to locate a date which is somewhere in an 8 GB log (text).
Can I somewhat bypass a full sequential read, and first do binary splits of the file (size), or somehow navigating the filesystem ...
5
votes
1answer
132 views
counting multiple patterns in a single pass with grep?
I've written a grep loop to iteratively count DNA trinucleotides within a gzipped DNA fasta file containing DNA sequences e.g.
declare -a tri=(AAA AAC AAG AAT CAA .. etc)
for i in ${tri[@]}
do
...
-1
votes
1answer
56 views
Importing an excerpt from a file into a script
I'm trying to import an excerpt from a file into a script for processing.
LIST=$(sed '1,/+++NETWORKLIST+++/d' < /path/to/file | sort -t ";" -k2,2r)
My problem is that this script is not deleting ...
3
votes
4answers
201 views
Replace all newlines to space except the last
How can I replace all newlines with space except the last newline.
I can replace all newline to space using tr but how I can do it with some exceptions?
0
votes
1answer
201 views
How to print gmail inbox messages
I want to print inbox messages one by one (like cat someFile) so that I can parse the message contents.
something like printGmail InboxMesg1 | grep some | sed some
Using curl I can access the ...
7
votes
7answers
4k views
Text processing - join lines with commas
I have more than 1000 lines in a file. The file starts as follows (line numbers added):
1. Station Name
2. Station Code
3. A N DEV NAGAR
4. ACND
5. ABHAIPUR
6. AHA
7. ABOHAR
8. ABS
9. ABU ROAD
10. ...
8
votes
2answers
13k views
How do I delete the first n lines of an ascii file using shell commands?
I have multiple files that contain ascii text information in the first 5-10 lines, followed by well-tabulated matrix information. In a shell script, I want to remove these first few lines of text so ...
3
votes
2answers
193 views
Bash-script. Shift seconds
Maybe somebody can help me. In bash I don't know how to do that. I need to do a bash-script. At stdin I have .srt file of subtitles in this format:
num
HH:MM:SS,SSS --> HH:MM:SS,SSS
text line 1
...
1
vote
1answer
220 views
Problem with sed on a array containing strings containing spaces
I have a array looking like this:
array=("(1 2 3) (123)" "2 31 (231)" "4 5 1 (451)" "(te)xt (1234)")
This array is a example. It does not look like this but its structure is the same (the strings ...
0
votes
1answer
155 views
Copy file while replacing text in it
I'm writing a script to publish a webapp. While copying files, I must replace a placeholder current_date in a file with the current date.
I would start with something like this to define the date ...
4
votes
3answers
208 views
Parsing string token with bash
I have this output (from a previous command):
aaa something
bbb someother
ccc blabla
For each line, I would like to create a file whose name is the first token, and whose ...
2
votes
6answers
3k views
bash - replace space with new line
How can I replace spaces with new lines on an input like:
/path/to/file /path/to/file2 /path/to/file3 /path/to/file4 /path/to/file5 etc...
To obtain the following:
/path/to/file
/path/to/file2
...
8
votes
4answers
212 views
Split the file and put it in corresponding data structure?
I have a file which contains the single line below:
{machineA=[0, 1024, 4, 1028], machineB=[1, 1025, 5, 1029]}
in which I have two datasets:
machineA=[0, 1024, 4, 1028]
machineB=[1, 1025, 5, 1029]
...
1
vote
3answers
683 views
remove particular characters from a variable using bash
I want to parse a variable (in my case it's development kit version) to make it dot(.) free. If version='2.3.3', desired output is 233.
I tried as below, but it requires . to be replaced with another ...
5
votes
5answers
3k views
Parsing a delimited text file in bash as command arguments
I have a text file split up like so:
field1,field2,field3
xield1,xield2,xield3
dield1,dield2,dield3
gield1,gield2,gield3
Each of these columns will be a parameter to a program, and I would like ...
2
votes
2answers
120 views
stripping out the last two [end] with sed?
I'm working on a script that improves the fluxbox 'menu', and my script has this line:
sed -i 's/\[end]//g' ~/.fluxbox/menu;sed -i '/^\s*$/d' ~/.fluxbox/menu
but this has the unfortunate effect of ...
2
votes
2answers
3k views
Insert text in specific lines of a file?
How can insert some text in specific lines of a file? What is most simplest method that I can use? (bash, sed, awk?)
What I want to do, might be simple, but I don't know where I should start. It's ...
2
votes
5answers
148 views
Read contents in a line in bash
I have a file with contents in this order which is separated by space
4096 1230 4560 1024.... n
How can i read each number and pass it on to another command, eg divide each number by 1024.
3
votes
2answers
343 views
How to find frequency of occurrences of strings contained in a file?
I have a file that contains a list of URLs of the form
EDIT
http://www.google.com/absd/siidfs/kfd837382$%^$&,
www.google.com,
google.com
yahoo.com/list/page/jhfjkshdjf...
I ...
4
votes
4answers
188 views
How do I aggregate data from many files into one file?
I have this directory structure for about 100 users.
users
- user1
- info.txt
- user2
- info.txt
- user3
- info.txt
...
Inside the info.txt files, the contents look like this.
5 ...
3
votes
3answers
147 views
Transforming text to tabular form
I have a text file with the following structure:
aaa
bbb
ccc
ddd
eee
fff
1
2
3
4
5
6
1.1
1.2
1.3
1.4
1.5
1.6
ggg
hhh
iii
jjj
kkk
lll
7
8
9
10
11
12
2.1
2.2
2.3
2.4
2.5
2.6
and I want the ...
3
votes
5answers
177 views
Comparing Indices of two strings
I have two double quoted strings of same length, that look like this:
"$con" - (consists of spaces and *'s):
* ****** *** ** * **
and ...