The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-31-2007
Registered User
 

Join Date: Jan 2006
Posts: 145
Unhappy sed question please help

I have many of this similar lines in a file and it is always start with number 7. How can replace this Whole-Line with something that I want.

7 ;0;12 ;3;0; ; ; ;ABCD ;n;n; ; ; ; ; ;

I tried:

sed 's/^7/tom/g' file

I get:

tom ;0;12 ;3;0; ; ; ;ABCD ;n;n; ; ; ; ; ;

Also,

there are lines that may start with 70, 71,.....79. How can I make it works for just "7"

For example:
79 ;0;12 ;3;0; ; ; ;ABCD ;n;n; ; ; ; ; ;

I will get:
tom9 ;0;12 ;3;0; ; ; ;ABCD ;n;n; ; ; ; ; ;

Many Thanks!
Reply With Quote
Forum Sponsor
  #2  
Old 05-31-2007
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
sed 's/^7 ;.*$/tom/' < infile > outfile
Reply With Quote
  #3  
Old 05-31-2007
Registered User
 

Join Date: Jan 2006
Posts: 145
Unhappy

Thank you for the reply! but it is not working!
Reply With Quote
  #4  
Old 05-31-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
replace whole line?
Code:
sed 's/^7.*/tom/g'
Reply With Quote
  #5  
Old 05-31-2007
Registered User
 

Join Date: Jan 2006
Posts: 145
Thanks! It works!
Reply With Quote
  #6  
Old 05-31-2007
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Quote:
Originally Posted by bobo
Thanks! It works!
No it doesn't.

You said
Quote:
there are lines that may start with 70, 71,.....79. How can I make it works for just "7"
The sed command given will also replace entire lines starting with 70, 71, 79 - whatever, e.g.
Code:
$ echo "79 ;sadjsajdds" | sed 's/^7.*/tom/g'
tom
Are you sure this is what you want?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:33 PM.


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