Insert a line at specific line number with sed or awk
sed -i ‘8i This is Line 8’ FILE inserts at line 8 This is Line 8 into file FILE -i does the modification directly to file FILE, no output to stdout, as mentioned in the comments by glenn jackman.
sed -i ‘8i This is Line 8’ FILE inserts at line 8 This is Line 8 into file FILE -i does the modification directly to file FILE, no output to stdout, as mentioned in the comments by glenn jackman.
You can use cut to access the second field: cut -f2 Edit: Sorry, didn’t realise that SVN doesn’t use tabs in its output, so that’s a bit useless. You can tailor cut to the output but it’s a bit fragile – something like cut -c 10- would work, but the exact value will depend on … Read more
You can use the -i flag which makes your pattern case insensitive: grep -iF “success…” file1 Also, there is no need for cat. grep takes a file with the syntax grep <pattern> <file>. I also used the -F flag to search for a fixed string to avoid escaping the ellipsis.
awk ‘{sum+=$3}; END {printf “%f”,sum/NR}’ ${file}_${f}_v1.xls >> to-plot-p.xls print will insert a newline by default. You dont want that to happen, hence use printf instead.
Use -F [field separator] to split the lines on “s: awk -F ‘”‘ ‘{print $2}’ your_input_file or for input from pipe <some_command> | awk -F ‘”‘ ‘{print $2}’ output: A B C D
You can use awk: awk ‘{ sum += $1 } END { print sum }’ file
Have you tried: echo “12|23|11″ | awk ‘{split($0,a,”|”); print a[3],a[2],a[1]}’
you can try with awk: awk ‘/blah/{getline; print}’ logfile
The delimiter can be a regular expression. awk -F'[/=]’ ‘{print $3 “\t” $5 “\t” $8}’ file Produces: tc0001 tomcat7.1 demo.example.com tc0001 tomcat7.2 quest.example.com tc0001 tomcat7.5 www.example.com
In order of appearance, the languages are sed, awk, perl, python. The sed program is a stream editor and is designed to apply the actions from a script to each line (or, more generally, to specified ranges of lines) of the input file or files. Its language is based on ed, the Unix editor, and … Read more