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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can I insert character to end of file? umen UNIX for Dummies Questions & Answers 1 01-29-2008 04:47 AM
insert some text to a file log bucci Shell Programming and Scripting 4 05-09-2007 04:19 AM
insert text into top of file jimbob Shell Programming and Scripting 1 09-22-2006 02:46 PM
Insert text file at a certain line. insania Shell Programming and Scripting 4 07-31-2006 11:46 PM
SED- Insert text at top of file MBGPS Shell Programming and Scripting 12 07-03-2002 06:48 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-10-2005
Registered User
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
Edit and insert character in a text file

Hello All,

Can somebody please help me how to accomplish the following :

I have a text file called data.txt that has the following information :

M|88494-998494
M|98jd#0094
M|88394-994049
M|GFG9980#009944
and so on...


I need to replace the value of M to either "S" or "X" depending on whether there is "-" or "#" in the record. If there is a "-"m replace it with "S".....

Can I just use SED? thnaks!

Joseph
Reply With Quote
Forum Sponsor
  #2  
Old 06-10-2005
Registered User
 

Join Date: Nov 2003
Posts: 11
sed

Quote:
Originally Posted by negixx
Hello All,

Can somebody please help me how to accomplish the following :

I have a text file called data.txt that has the following information :

M|88494-998494
M|98jd#0094
M|88394-994049
M|GFG9980#009944
and so on...


I need to replace the value of M to either "S" or "X" depending on whether there is "-" or "#" in the record. If there is a "-"m replace it with "S".....

Can I just use SED? thnaks!

Joseph

sed -e '/\-/ s/M/S/' m.txt -ne '/\#/ s/M/X/' m.txt

I have not tested it. Pls. check.

Ram
Reply With Quote
  #3  
Old 06-10-2005
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,644
sed -e '/\-/ s/M/S/' -e '/\#/ s/M/X/' data.txt
Reply With Quote
  #4  
Old 06-10-2005
Registered User
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
Thank you very much! I will try it out....

Joseph
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0