deleting line using sed

Discussion in 'Mac Programming' started by rita1985, Dec 25, 2007.

  1. rita1985 macrumors newbie

    Joined:
    Dec 25, 2007
    #1
    LOGFILE=/tmp/rc.net.out # LOGFILE is where all stdout goes.

    What sed command should i use in order to only display LOGFILE=/tmp/rc.net.out

    I try using this sed "/#/d" tmp1.txt > tmp2.txt but it delete the whole line away
     
  2. Baron58 macrumors 6502

    Joined:
    Feb 19, 2004
    #2
    sed s/' #'.*$//g tmp1.txt > tmp2.txt

    Substitute literal SPACE#anycharacter zero or more times until end of line with "nothing", globally.

    I would tend to do: cat tmp1.txt | sed s/' #'.*$//g > tmp2.txt
    ...but whatever.
     
  3. rita1985 thread starter macrumors newbie

    Joined:
    Dec 25, 2007
    #3
    deleting line using sed

    i having this error --- > sed: garbled command s/

    How can i solve it?
     
  4. fimac macrumors member

    Joined:
    Jan 18, 2006
    Location:
    Finland
    #4
    cut is great for simple cases

    Your options include sed, awk, and cut (which I think is simplest in this case).

    Code:
    cat tmp | sed -e 's: *#.*$::g'
    cat tmp | awk -F# '{print $1}'
    cat tmp | cut -d# -f1
    
    Perl can also be used, but I leave that as an exercise for the reader ;)
     
  5. Baron58 macrumors 6502

    Joined:
    Feb 19, 2004
    #5
    Did you make a typo, or did you copy/paste what I wrote? What *nix are you using it on?
     
  6. fimac macrumors member

    Joined:
    Jan 18, 2006
    Location:
    Finland
    #6
    The space needs to be a tab, if copy+paste is expected to work. Just FYI :) [Using bash on 10.5.2]

    Generally, I recommend quoting the whole of the sed expression; this means the shell does not "get in our way" -- and so it is easier to debug.
     
  7. rita1985 thread starter macrumors newbie

    Joined:
    Dec 25, 2007
    #7
    deleting line using sed

    i am using MS-Dos batch file.
     
  8. rita1985 thread starter macrumors newbie

    Joined:
    Dec 25, 2007
    #8
    deleting lines using sed

    i have found the solution.

    sed "s/# LOGFILE.*goes./ /g" tmp0.txt > tmp1.txt

    This command delete all the words that is in between #LOGFILE and goes.

    cheers (^-^)
     

Share This Page