LinuxQuestions.org
Review your favorite Linux distribution.
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, 12:32 PM   #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 02:35 PM.
 
Old 02-27-2011, 01: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 01:39 PM.
 
1 members found this post helpful.
Old 02-27-2011, 02: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:09 PM
Linux Sed Command Help anirudh Programming 4 08-31-2004 03:09 PM
Linux sed command kml100 Linux - Newbie 4 05-28-2004 04:27 PM


All times are GMT -5. The time now is 07:50 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration