Click to See Complete Forum and Search --> : sed's not working


trashthing
02-13-2003, 04:07 PM
hi. i want to remove patterns w/ sed, but it's not working. this is what i do:

sed /pattern/d (the file)

after that, it's still there. why is this happening?

bwkaz
02-13-2003, 05:07 PM
While I do believe the d command deletes stuff, perhaps trying a sed command of 's/pattern//g' would work instead?

Or actually, what you're doing isn't going to change the file. It'll read the lines out of the file, change them, and print them to stdout. If you want to keep the changes and not print them to the screen, redirect output, like:

sed -e '/pattern/d' (the file) >(the file)~
mv -f (the file)~ (the file)

Where you do the sed first, then move the tilde-ed file back over the original.

rbermejo
02-14-2003, 03:06 PM
try this :



it saves you the mv command, syntax-like 'sed' ,is faster ,and it feeds you ....your daily pie !

perl -p -i -e s/perl/ruby/g file

-r.

trashthing
02-15-2003, 03:16 PM
thanks, i had to do it this way:

sed -e /pattern/d (file) > (file)
mv -f (file) (file)

thanks again. this helps me alot.

baldguy
02-15-2003, 08:55 PM
Just as a point, I believe if you use the g/regex/d expression it deletes an entire line, not just the pattern that you match.