Tuesday, June 24, 2008

Update a file based on another file-sed

First file:

$ cat ranks.txt

Second file (Exception file)

$ cat except_ip.txt


- based on the entries in the second file, i.e. except_ip.txt, update the second fileld of first file i.e. ranks.txt in such a way that : if the IP address is present in the second file, make the rank(2nd field of ranks.txt) to 0, rest entries in ranks.txt should be unchanged.


required output:

The awk code:

$ awk 'BEGIN {FS=OFS=":"}
FNR==NR {ex[$1]; next}
{ $2 = ($1 in ex) ? "0" : $2; print }
' except_ip.txt ranks.txt


No comments:

© Jadu Saikia www.UNIXCL.com