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 can I insert character to end of file? umen UNIX for Dummies Questions & Answers 1 01-29-2008 07:47 AM
insert some text to a file log bucci Shell Programming and Scripting 4 05-09-2007 07:19 AM
insert text into top of file jimbob Shell Programming and Scripting 1 09-22-2006 05:46 PM
Insert text file at a certain line. insania Shell Programming and Scripting 4 08-01-2006 02:46 AM
SED- Insert text at top of file MBGPS Shell Programming and Scripting 12 07-03-2002 09:48 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 06-10-2005
negixx negixx is offline
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
  #2 (permalink)  
Old 06-10-2005
ramkumar_gr ramkumar_gr is offline
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
  #3 (permalink)  
Old 06-10-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,211
sed -e '/\-/ s/M/S/' -e '/\#/ s/M/X/' data.txt
  #4 (permalink)  
Old 06-10-2005
negixx negixx is offline
Registered User
  
 

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

Joseph
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 12:40 AM.


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