Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rita1985

macrumors newbie
Original poster
Dec 25, 2007
13
0
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
 

Baron58

macrumors 6502
Feb 19, 2004
450
3
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

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

macrumors newbie
Original poster
Dec 25, 2007
13
0
deleting line using sed

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

How can i solve it?
 

fimac

macrumors member
Jan 18, 2006
95
1
Finland
cut is great for simple cases

What sed command should i use...

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 ;)
 

fimac

macrumors member
Jan 18, 2006
95
1
Finland
cat tmp1.txt | sed s/' #'.*$//g > tmp2.txt

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.
 

rita1985

macrumors newbie
Original poster
Dec 25, 2007
13
0
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 (^-^)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.