The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-31-2007
jkl_jkl jkl_jkl is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 46
awk: find and replace in certain field only, help needed

I got a sample file like this.

$ cat test
12|13|100|s
12|13|100|s
100|13|100|s
12|13|100|s

I want to replace all 100 by 2000 only in 3rd field using "awk"

This is replacing all 100's :-(
$ awk -F "|" '{gsub( /100/,"2000");print}' test
12|13|2000|s
12|13|2000|s
2000|13|2000|s
12|13|2000|s

I tried using something like this also - '$3 ~ /100/
but no luck :-(

Please help.

HTH,
jkl_jkl