R rita1985 macrumors newbie Original poster Dec 25, 2007 13 0 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
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
B Baron58 macrumors 6502 Feb 19, 2004 450 3 Dec 25, 2007 #2 rita1985 said: 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 Click to expand... 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.
rita1985 said: 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 Click to expand... 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.
R rita1985 macrumors newbie Original poster Dec 25, 2007 13 0 Dec 25, 2007 #3 deleting line using sed i having this error --- > sed: garbled command s/ How can i solve it?
F fimac macrumors member Jan 18, 2006 95 1 Finland Dec 26, 2007 #4 cut is great for simple cases rita1985 said: What sed command should i use... Click to expand... 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
cut is great for simple cases rita1985 said: What sed command should i use... Click to expand... 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
B Baron58 macrumors 6502 Feb 19, 2004 450 3 Dec 26, 2007 #5 rita1985 said: i having this error --- > sed: garbled command s/ How can i solve it? Click to expand... Did you make a typo, or did you copy/paste what I wrote? What *nix are you using it on?
rita1985 said: i having this error --- > sed: garbled command s/ How can i solve it? Click to expand... Did you make a typo, or did you copy/paste what I wrote? What *nix are you using it on?
F fimac macrumors member Jan 18, 2006 95 1 Finland Dec 26, 2007 #6 Baron58 said: cat tmp1.txt | sed s/' #'.*$//g > tmp2.txt Click to expand... 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.
Baron58 said: cat tmp1.txt | sed s/' #'.*$//g > tmp2.txt Click to expand... 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.
R rita1985 macrumors newbie Original poster Dec 25, 2007 13 0 Dec 26, 2007 #7 deleting line using sed i am using MS-Dos batch file.
R rita1985 macrumors newbie Original poster Dec 25, 2007 13 0 Jan 1, 2008 #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 (^-^)
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 (^-^)