Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Mar 092010

Speedup sed search and replace


If you have a very large file, sometimes you can speed up sed by using the following method:

Original method:

# sed 's/foo/bar/g' filename

Optimized method:

# sed '/foo/ s/foo/bar/g' filename

The second method is faster since substitution is only performed when the search string is found.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>