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

Monday, August 27, 2007

Content of content of a variable !

Digest for today morning: use of ${!VARIABLE} , learnt from Navojit Dutta(UNIX forum)

$ cat content
MYVAR=$1
DUMMY1="This is tricky"
DUMMY2=24
echo ${!MYVAR}


$ ./content DUMMY1
This is tricky

$ ./content DUMMY2
24

© Jadu Saikia http://unstableme.blogspot.com