Saturday, June 7, 2008

Remove/Delete column - awk


Input filea is # delimited.


$ cat filea
a#b#c#0
d#e#f#1
g#h#i#1



Purpose:
Remove the 2nd and 3rd column from filea



$ awk 'BEGIN{FS=OFS="#"}{$2=$3=""}{print}' filea

a###0
d###1
g###1



$ awk 'BEGIN{FS=OFS="#"}{$2=$3="";gsub(FS"+",FS)}1' filea

a#0
d#1
g#1


As I told earlier , the 1 in the above code is similar to {print $0}.


Similar Post:
- Replace the 100's in 3rd field with different numbers

No comments:

© Jadu Saikia www.UNIXCL.com