[Nottingham] sed question

Simon Amor simon at leaky.org
Sat Sep 24 19:07:55 BST 2005


On 24 Sep 2005, at 18:41, David Aldred wrote:
> How do I use sed to make changes to a file, with the changes being  
> written
> back to the file?
>
> sed <expr> testfile just puts the results onto stdout; using  
> '>testfile'at the
> end results in an empty file....
>
> So far I've got to:
>
> sed <expr> testfile > tempfile && mv -f tempfile testfile
>
> which works, but seems a bit inelegant...

It's not sed, but how about:

perl -spi -e 's/xxx/yyy/g' testfile

You can even have perl make a backup first:

perl -spi.bak -e 's/xxx/yyy/g' testfile

That will leave testfile.bak in the same directory as testfile.

   Simon
-- 
Simon Amor
simon at leaky.org
http://www.leaky.org/





More information about the Nottingham mailing list