Results 1 to 10 of 10
The sed command i.e stream editor , why does it need the starting 's' option
I have something like this
Code:
sed 's/cat/dog/' pets
It is supposed to replace all ...
- 06-19-2009 #1
sed 's/cat/dog' pets
The sed command i.e stream editor , why does it need the starting 's' option
I have something like thisIt is supposed to replace all cat with dogs in the file pets. So does that 's' means to search , In the man pages -s specifies separate ???Code:sed 's/cat/dog/' pets
Only if I could understand the man pages
Registered Linux user #492640
OS: RHEL4,5 ,RH 9,Ubuntu
- 06-19-2009 #2
a little more help
I wonder what exactly these commands do . and also what does this one doCode:sed -e 's/cat/dog/g' -e 's/cat/dog/g' pets
thanksCode:sed -f myedits pets
Only if I could understand the man pages
Registered Linux user #492640
OS: RHEL4,5 ,RH 9,Ubuntu
- 06-19-2009 #3Just Joined!
- Join Date
- Apr 2009
- Posts
- 33
- 06-19-2009 #4
thanks but what about the second one?
Only if I could understand the man pages
Registered Linux user #492640
OS: RHEL4,5 ,RH 9,Ubuntu
- 06-19-2009 #5Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
For the 2nd one, the manpage for sed states:
So in your example file myscripts would contain the command 's/cat/dog/g' in it (minus the single quotes). The advantage of using a file is that some sed commands can get quite long so it's easier to have them in a file and then specify that file when you run sed.-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
- 06-19-2009 #6
thanks lomcevak but what does the 'e' do? in the second part code 1
Only if I could understand the man pages
Registered Linux user #492640
OS: RHEL4,5 ,RH 9,Ubuntu
- 06-19-2009 #7Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
You really do have to start trying to understand manpages. For the -e option it states.
What this allows you to do is execute more that one sed command one a file. Your example isn't a good one because you're performing the same substitution twice.-e script, --expression=script
add the script to the commands to be executed
This would make more sense.Code:sed -e 's/cat/dog/g' -e 's/cat/dog/g' pets
In my example you're substituting cat with dog AND mice with rat.Code:sed -e 's/cat/dog/g' -e 's/mice/rat/g' pets
You could also do this without the -e option by using the semi-colon( ; ) to separate sed commands like this:
Code:sed 's/cat/dog/g; s/mice/rat/g' pets
- 06-19-2009 #8
thanks
see i if had just ended on man pages i wouldn't have learned the ';' thing.Only if I could understand the man pages
Registered Linux user #492640
OS: RHEL4,5 ,RH 9,Ubuntu
- 06-19-2009 #9Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Well yes and no. In the sed manpage it also says:
So in the case of sed the manpage is telling you to refer to other documentation for a better explanation of sed.This is just a brief synopsis of sed commands to serve as a reminder
to those who already know sed; other documentation (such as the tex-
info document) must be consulted for fuller descriptions.
- 06-19-2009 #10
lol .......................
Only if I could understand the man pages
Registered Linux user #492640
OS: RHEL4,5 ,RH 9,Ubuntu


Reply With Quote
