Friday, August 31, 2007
Replace the 100's in 3rd field with different numbers.
Problem : Replace the 100's in 3rd field with different numbers.
Sample file
$ cat fl
12|13|100|s
12|13|100|s
100|13|100|s
12|13|100|s
Output:
$ awk 'BEGIN{OFS=FS="|"}$3==100{$3=NR*131}{print}' fl
12|13|131|s
12|13|262|s
100|13|393|s
12|13|524|s
And if you want to add a dummy field as the 4th field(insert) with value as "104"
$ awk 'BEGIN{OFS=FS="|"}{$3=$3"|104"}{print}' fl
12|13|100|104|s
12|13|100|104|s
100|13|100|104|s
12|13|100|104|s
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
No comments:
Post a Comment