Tag Info

New answers tagged

0

My input data file abc.txt has this "20131008","0004","0568","98" I ran this command to replace the text nawk -F, -vOFS=',' '{gsub("0568","0808",$3); print }' abc.txt In the output the delimiter "," is replaced with a space. The output looks like this "20131008" "0004" "0568" "98". Can someone please help with this? I tried to replace the -vOFS but ...


1

{ nl -bpH -w1 | sed 's/^\([0-9]*\)[ \t]*\([^H]*.\)/\2\1/' } <<\DATA ... 1562 first part 1563 H col3 H col4 1564 H col3 H col4 ... 3241 H col3 H col4 3242 third part DATA OUTPUT ... 1562 first part 1563 H1 col3 H col4 1564 H2 col3 H col4 ... 3241 H3 col3 H col4 3242 third part That's the fastest way I can imagine it ...


1

With perl: perl -pe 's/\bH\b\K/++$i/e' file You can replace -pe with -pi.back -e for in-place editing with the original saved as file.back or -pi -e for no backup.


1

Try this: awk 'BEGIN { hNum = 1; } { if ($2 == "H") { $2 = "H" hNum; hNum++; } print $0; }' yourFile > outFile It run awk using space as separator, so $2 is the second token of each line and if $2 is equal to "H", then replace it with "H" followed by number started from 1. Finally print out line.


7

You can for example use this: $ awk '/H/{sub("H", "H"++v)}1' file 1562 first part 1563 H1 col3 H col4 1564 H2 col3 H col4 3241 H3 col3 H col4 3242 third part ... This looks for those lines containing H and replaces that H with H together with a variable we keep incrementing. Note you could use gsub() instead of sub() if you wanted to perform ...


0

egrep -v ^'(#|$)' file.txt Strips all comments and empty lines from file.txt



Top 50 recent answers are included