![]() |
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 |
| Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| replace single field out of 60 | ajp7701 | Shell Programming and Scripting | 2 | 04-21-2008 07:17 PM |
| how to replace field for each record | happyv | Shell Programming and Scripting | 12 | 06-26-2007 07:56 AM |
| Replace password field using ed/sed | munch | UNIX for Dummies Questions & Answers | 6 | 04-30-2007 11:01 PM |
| find pattern and replace another field | sergiioo | Shell Programming and Scripting | 3 | 04-11-2007 12:19 AM |
| Replace 10th Field by 2 | PradeepRed | Shell Programming and Scripting | 2 | 01-19-2006 03:46 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Replace field in csv
Hi, I need to replace a field (field 5) in a csv file, based on the content of another field (field 2), something like this:
actual file: field1, field2, filed3, field4, field5, field6 01,232,abb-pan,679,,pan 02,565,cdf-pan,683,,pan the result should be: 01,232,abb-pan,679,PASSED,pan **************** so, if field2 value is 232, then write PASSED in field 5 Im familiar with awk, i tried this: awk -F, '{ if ($2 == "232") { pass_ref="PASSED" **** I'm stuck here, how I replace the field5... in the same file...???*** thanks in advanced.... |
|
||||
|
you don't want to redirect to the same file that your reading! as you found out this will truncate the data file. Redirect to a new filename.
ie: Code:
awk -F, 'BEGIN{OFS=","}{if($2 == 232){$5="PASSED";print}}' alumni*.csv > newfile.csv
|
|
||||
|
Thanks
I can achieve what I need by redirecting to another file, and then renameming those files...
Thanks a lot.... |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|