Tagged Questions
0
votes
1answer
44 views
Counting by number of occurrences in first column
I have an input file like this:
ATTACK-RESPONSES id check returned root
BACKDOOR ACKcmdC trojan scan
BACKDOOR hack-a-tack attempt
BACKDOOR WinCrash 1.0 Server Active
ICMP Destination Unreachable ...
1
vote
0answers
58 views
error occur when i run awk command write in .sh file and run in cygwin terminal
i have cygwin terminal for run shell script(.sh ) file...it work good..but when i add awk command in shell script and then run Error occur
/usr/bin/gawk.exe: error while loading shared libraries: ...
3
votes
2answers
126 views
SED: How can I print every line after first instance of string using Sed?
I have a file with a similar format...
16:28 asdfasdf
16:29 4398upte
16:30 34liuthr
16:31 34tertio
How can I use SED to print out every line including and after the line with "16:30"?
The result ...
1
vote
1answer
56 views
Subtract files from one another recursively between two similar directories
I'm trying to concoct a way to grab two (nearly identical) directories and show me the difference between all files in the two directories.
Looking for two different things:
1- List all files ...
0
votes
1answer
96 views
Grep issue (match two strings on same line)
Here I have some grep command which is not working correctly:
cat file1.txt:
apples
Date: Sun, 24 Feb 2013 8:14:06 -0800
peaches melons
cherry sky cloud
green purple
yellow
cat file2.txt:
apples
...
0
votes
1answer
82 views
Combining multiple data files with header while also adding a data column
I have multiple tab delimited data files that are separated by month in the format jan06.txt, feb06.txt, ..., dec07.txt.
Within each file, it looks something like:
Header1 Header2 Header3 ...
Data1 ...
0
votes
3answers
274 views
Parse and remove parts of strings between delimiters
I would like to go through a file and remove certain sequences in between delimiters.
For example
drw---- 00000000 11111111 0 ./a/
drw---- 00000000 11111111 0 ./b/
d------ 00000000 ...
3
votes
4answers
2k views
Print back-reference in regular expression
I was hoping for a way to make sed replace the entire line with the replacement (rather than just the match) so I could do something like this:
sed -e "/$some_complex_regex_with_a_backref/\1/"
and ...
1
vote
4answers
157 views
sed -e “s/-.*$//”
What does the -.*$/ in this command mean? Please help me decipher this.
echo -n full | sed -e "s/-.*$//"
I know what sed does and all that, I just want to know what this -.*$ part is.
0
votes
1answer
281 views
How to insert thousand separator with `sed`?
I want to insert thousand separator into a number sequence with sed and this ugly RE sed -e :a -e 's/\(.*[0-9]\)\(\([0-9]\{3\}\)\(,[0-9]\{3\}\)*\(\.[0-9]*\)\)/\1,\2/;ta' [filename].
Is there a more ...
0
votes
3answers
318 views
Oneliner for multiline regex s/,\n]/]/g?
Can someone provide a simple one-liner to remove certain line breaks?
In vim I use %s/,\n]/]/g
This should be possible with a very simple one-liner IMHO, but how?
0
votes
1answer
332 views
Sed pattern for multiple lines
I want to remove all create table statements from a mysql script, but the statement runs over multiple lines.
Like this: Create table ......NEWLINE... NEWLINE... NEWLINE....;
So I tried this ...
0
votes
1answer
122 views
seq with regex, error message for mysql quotes
Is there some tool that auto quotes regex for seq?
I can't figure out what I'm doing wrong. I always get this error unterminateds' command`
sed -i 's/INSERT INTO `tablename.*`/INSERT INTO ...
0
votes
4answers
179 views
Extract substring using bash
All,
I have file names that will be always in the following format
"rX_Q_Y_filename.mp3" where X and Y are numbers (0-9).
FYI, X and Y in the filename can be 1 or more digits
example ...
0
votes
2answers
376 views
Truncate all files in a directory after underscore?
I have a directory with a couple thousand images in it. Most of them have sensible filenames like SD-000.tif SD-001.tif BX-000.tif etc...
However probably ~25% of them have names like BX-003_old.tif ...
3
votes
2answers
347 views
sed: Replace an unknown number of patterns on the same line
I'm trying to use sed to search for a certain 'primary' pattern that may exist on several lines, with each primary pattern followed by an --unknown-- number of 'secondary' patterns.
The lines ...
0
votes
2answers
239 views
Shell: Trim whitespace in the beginning of files
I have 20k files in here, and at least 1000 of them having white space in the beginning.
How can I remove whitespace with sed for example? The problem is, that it may apear some duplicated file ...
4
votes
2answers
877 views
Use sed command to replace , appearing between numbers
I have a CSV file where data are in the following format
|001|,|abc,def|,123456,789,|aaa|,|bbb|,444,555,666
I want to replace only those "," that appears between numbers with some other character ...
0
votes
2answers
558 views
Moving characters to the end of line (EOL) with SED
Any time the word “The” appears at the beginning of a line, I want to move it to the end of the line and capitalize the new first word in the line. For example, “The heaven” becomes “Heaven the”. I'm ...
0
votes
8answers
221 views
Unix command to list the portion of the end of a log file from a line containing only hyphens to end of file
I have a long log file where each entry begins with a line containg only hyphens.
0
votes
1answer
204 views
How to use sed or AWK to separate a string (NOT string in files)
How can I separate .sh files into a list?
I have tried:
ls *.sh | xargs sed 's/\n/ /g' > out.txt
The return of ls *.sh is a long string with '\n' in the middle.
7
votes
4answers
3k views
Better way to do “echo $x | sed …” and “echo $x | grep …”
I often find this in scripts (and, I have to admit, write it myself):
a=`echo $x | sed "s/foo/bar/"`
or
if echo $x | grep foo
then
...
fi
Consider "foo" to include some regex stuff.
I feel ...
0
votes
1answer
502 views
Replace filename with filepath with sed
I want to replace the string
/opt/local/lib/ruby/gems/1.8/gems/cucumber-0.3.99/lib/cucumber.rb
with the string
/opt/local/lib/ruby/gems/1.8/gems/cucumber-0.3.99/lib/
on the command line, probably ...