Find the answer to your Linux question:
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 ...
  1. #1
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    sed 's/cat/dog' pets

    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 cat with dogs in the file pets. So does that 's' means to search , In the man pages -s specifies separate ???
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  2. #2
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    a little more help

    I wonder what exactly these commands do .
    Code:
    sed -e 's/cat/dog/g'  -e 's/cat/dog/g' pets
    and also what does this one do
    Code:
    sed -f myedits pets
    thanks
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  3. #3
    Just Joined!
    Join Date
    Apr 2009
    Posts
    33
    Quote Originally Posted by vickey_20 View Post
    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 cat with dogs in the file pets. So does that 's' means to search , In the man pages -s specifies separate ???
    s as in 'substitute'
    by the way if you want all the 'cat' replaced by 'dog' you must
    type this

    sed 's/cat/dog/g' pets

    (g as in global)

  4. #4
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    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

  5. #5
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    For the 2nd one, the manpage for sed states:

    -f script-file, --file=script-file

    add the contents of script-file to the commands to be executed
    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.

  6. #6
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    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

  7. #7
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    You really do have to start trying to understand manpages. For the -e option it states.

    -e script, --expression=script

    add the script to the commands to be executed
    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.

    Code:
    sed -e 's/cat/dog/g'  -e 's/cat/dog/g' pets
    This would make more sense.

    Code:
    sed -e 's/cat/dog/g'  -e 's/mice/rat/g' pets
    In my example you're substituting cat with dog AND mice with rat.

    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

  8. #8
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    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

  9. #9
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Well yes and no. In the sed manpage it also says:

    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.
    So in the case of sed the manpage is telling you to refer to other documentation for a better explanation of sed.

  10. #10
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    lol .......................
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...