The UNIX and Linux Forums  


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



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
replace single field out of 60 ajp7701 Shell Programming and Scripting 2 04-21-2008 08:17 PM
Replace field in csv pcboss Linux 4 01-19-2008 06:24 PM
how to replace field for each record happyv Shell Programming and Scripting 12 06-26-2007 08:56 AM
replace a similar field in a file chiru_h Shell Programming and Scripting 2 11-01-2006 05:23 PM
Replace 10th Field by 2 PradeepRed Shell Programming and Scripting 2 01-19-2006 03:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-12-2008
prvnrk prvnrk is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 138
replace a field in a CSV file

Hello all,

I've a CSV file and need to replace 5th field if its value is "X".

The exact requirement is to replace 5th field (column) with "Y" if
a. it's value is "X" AND
b. the line must start with ABC string

i guess this can be done with awk. Pl help.

For security reasons, the actual file format and contents are changed.


Thanks
Prvn
  #2 (permalink)  
Old 11-12-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,435

Code:
awk '$1 ~ /^ABC/ && $5=="X"{$5="Y"}1' file

  #3 (permalink)  
Old 11-12-2008
prvnrk prvnrk is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 138
Thank you danmero,

It worked great.

I just had to add -vOFS="," to get the output with commas.


Thanks!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0