Monday, January 26, 2009

sed : inplace replacement

It is easy to open a file in vim and do a search replace - but if the file runs into huge sizes, a regular editor would not be able to perform search and replace tasks on it efficiently. For these situation, you need a "stream" editor. Here is an example for replacing "foo" with "bar" in a file called snafu.txt


sed -i -e 's/foo/bar/g' snafu.txt


Where:

-i : Is for inplace replacement

-e: sed script to be run on the file

No comments: