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



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
how to specify the column(field) in sed command jdhahbi Shell Programming and Scripting 4 01-22-2009 06:17 PM
ps command - time field nhatch UNIX for Dummies Questions & Answers 1 05-12-2008 11:15 AM
sed command to change 2nd field Julius Shell Programming and Scripting 4 10-08-2006 08:30 AM
PS Command Field akuma Linux 2 11-08-2005 09:49 AM
exec command and field descriptors.. moxxx68 UNIX for Dummies Questions & Answers 5 12-04-2004 05:58 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-03-2009
chandrakala chandrakala is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 13
where to specify the field name in SED command

HI Folks,
I know the solution to my question is very easy but i could not find it out.

There is CSV file with 20 fields with 5 rows contains different data as below:

FBINV,LVO71,GAMFR1,D,104164,16677.36,20090625,102135,20090529,7267,KG,,,,0,,,,DTD,,O,O,,,,,,,,,30058 8136
FBINV,LVO71,GAMFR1,D,104164,16677.36,20090625,102135,20090529,7267,KG,,,,0,,,,DTD,,O,O,,,,,,,,,30058 8136
FBINV,LVO71,GAMFR1,D,104164,16677.36,20090625,102135,20090529,7267,KG,,,,0,,,,DTD,,O,O,,,,,,,,,30058 8136
FBINV,LVO71,GAMFR1,D,104164,16677.36,20090625,102135,20090529,7267,KG,,,,0,,,,DTD,,O,O,,,,,,,,,30058 8136
FBINV,LVO71,GAMFR1,D,104164,16677.36,20090625,102135,20090529,7267,KG,,,,0,,,,DTD,,O,O,,,,,,,,,30058 8136


I want to replace KG with K in field 11th in all the rows.

Can you please help me with a code to replace it in all the lines.processing line by line.There can be any number of rows in a file.


thanks a lot
  #2 (permalink)  
Old 07-03-2009
lathavim lathavim is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 73
Try this.

awk 'BEGIN { FS=OFS="," } /KG/ { $11 = "K" ; print }' filename
  #3 (permalink)  
Old 07-03-2009
jayan_jay jayan_jay is offline
Registered User
  
 

Join Date: Jul 2008
Location: Chennai
Posts: 40
sed 's/,KG,/,K,/g' <input-file>
  #4 (permalink)  
Old 07-04-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 457
Code:
 
I want to replace KG with K in field 11th in all the rows.
None of the solutions from jayan_jay or lathavim are checking for the 11th filed.

Bit change to lathamvim's solution :

Code:
awk 'BEGIN {FS=OFS=","} $11 ~/KG/ { $11 = "K" ; print }'  File_name.txt

Last edited by panyam; 07-04-2009 at 08:13 AM..
Sponsored Links
Reply

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 06:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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