![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| combining fields in two text fields | shocker | Shell Programming and Scripting | 3 | 01-16-2008 11:27 AM |
| cut: get either one or two fields | maxvirrozeito | Shell Programming and Scripting | 3 | 12-17-2007 11:58 AM |
| Cut Last 3 Fields | bourne | Shell Programming and Scripting | 4 | 01-11-2007 05:17 AM |
| Last fields | Khoomfire | UNIX for Advanced & Expert Users | 3 | 04-13-2006 05:03 PM |
| how to cut fields | rajan_ka1 | Shell Programming and Scripting | 1 | 12-29-2005 05:55 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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? |
|
||||
|
Hi,
i don't know exactly what you are trying to do, but if you only want to change line 2 of you file, this should be enough: Code:
sed "/^99/s/,,,/,0,0,/g" file HTH Chris |
| Sponsored Links | ||
|
|