The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 11-18-2008
ddurden7 ddurden7 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 5
Specifying and replacing fields with awk

#cat BATCH007.TXT
01,661060052,061000104,081118,0915,07,80,1,2/
99,,,2/

I have this file called BATCH007.TXT. I am trying to change fields 2 and 3 on line 2 to have zeroes. Like this:
01,661060052,061000104,081118,0915,07,80,1,2/
99,0,0,2/

I can use these commands to print identify the fields, which return a empty value, as they should:
head -2 BATCH007.TXT | tail -1l | awk '{FS=","} {print $2}'
head -2 BATCH007.TXT | tail -1l | awk '{FS=","} {print $3}'

I think I'm close. I added a gusb to the above command, but the output is incorrect:

head -2 BATCH007.TXT | tail -1l | awk -F "," '{gsub( $2,"0");print}' BATCH007.TXT > D.new

$cat D.new
01,661060052,0,081118,0915,07,80,1,2/
09090,0,0,020/0

Does anyone have any suggestions?