Menu:

Sed


April 30, 2008

I feel so lame that I never understood how to use sed properly before. Usually if I wanted to replace one string in a bunch of files I'd use a python script for the task or some other quick. custom solution. However, sed wins with

sed -i.bak -s -e s/old/new/g *.txt

I've been using Linux for 10 years and I just figured that out?! What is wrong with me?

Previous post | Next post

Jordan: 2008-04-30 15:51:21

Perl has a similar set of options to do exactly the same thing in case sed isn't handy, or the version available doesn't support it.

That said, I'm with you -- I wrote a /lot/ of scripts that created /tmp/$0.$$ tmp files each time I wanted to do the equivalent of an in-place replace. Only within the last year or two did I find the perl/sed "-i" option.

Dave Y.: 2008-05-21 15:31:06

I hate command line tools (for whatever reason) so I take care of this via regular expeessions and third-party applications.