Thread: Sed vs sed -e

    #1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,650
    Rep Power
    171

    Sed vs sed -e


    These 2 do exact same thing. What does -e do?
    Code:
    # sed "s/B/v/g" file2
    vehnam vehnam vehnam vehnam
    Code:
    # sed -e  "s/B/v/g" file2
    vehnam vehnam vehnam vehnam
    Manual says this but not sure:
    -e script, --expression=script

    add the script to the commands to be executed
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,376
    Rep Power
    1871
    They are the same thing, if you have only one script.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,436
    Rep Power
    1688
    Salem is correct, the -e parameter is only needed if you need more than one script to be run.
    Using your examples, try:

    Code:
    sed "s/B/v/g" "s/h/x/g" file2
    and then
    Code:
    sed -e "s/B/v/g" -e "s/h/x/g" file2
    Of course you could do it in the style of the first with:
    Code:
    sed "s/B/v/g" file2 | sed "s/h/x/g"
    but that is less efficient
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo