LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-27-2011, 11:32 AM   #1
kayjay1
LQ Newbie
 
Registered: Feb 2011
Posts: 4

Rep: Reputation: 0
Very new to Linux/Trying to understand the Sed command


I have tried to get the desired outcome and have failed.

the blue cat was chased by the brown dog
the blue cat was not chased by the brown dog

Line should read

the blue snake was chased by the brown snake
the blue car was not chased by the brown car.

I got the first line, but the words to be substituted in the second line did not change.

sed -e 's/cat/snake/' -e 's/dog/snake/' -e '/not/s/cat/car' -e 's/dog/cat/'

I have read and found that sed does not handle long line of command, so is there some way to break this up. I tried to use pipe and \n. Very new to this.

Last edited by kayjay1; 02-27-2011 at 01:35 PM.
 
Old 02-27-2011, 12:25 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

No, the length of the line is not the problem.
Quote:
vi test.txt
Code:
the blue cat was chased by the brown dog
the blue cat was not chased by the brown dog
Quote:
sed -e 's/cat/snake/' -e 's/dog/snake/' -e '/not/s/cat/car' -e 's/dog/cat/' test.txt
Code:
sed: -e expression #3, char 14: unterminated `s' command
Quote:
sed -e 's/cat/snake/' -e 's/dog/snake/' -e 's/dog/cat/' test.txt
Code:
the blue snake was chased by the brown snake
the blue snake was not chased by the brown snake
Quote:
sed -e 's/cat/snake/' -e 's/dog/snake/' -e 's/dog/cat/' -e 's/not chased by the brown snake/not chased by the brown car/' test.txt
Code:
the blue snake was chased by the brown snake
the blue snake was not chased by the brown car

Last edited by paulsm4; 02-27-2011 at 12:39 PM.
 
1 members found this post helpful.
Old 02-27-2011, 01:07 PM   #3
kayjay1
LQ Newbie
 
Registered: Feb 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you very much. Can you also try to help me understand this. I under the the first, second, and last expression. The third substitution has me stumped. -e 's/dog/cat'
I forgot to add the file name at the end of my line. I apologize for that. Thank you again.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
in sed command , I have difficulties to understand /1/2 seanrobi Programming 9 08-08-2010 12:09 PM
Linux Sed Command Help anirudh Programming 4 08-31-2004 02:09 PM
Linux sed command kml100 Linux - Newbie 4 05-28-2004 03:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration