Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

One-line shell script for find and replace (See related posts)

An equivalent of the other find-replace, except it's a one-liner that generates no temp files, and is more flexible:

perl -pi -e 's/find/replace/g' *.txt


Or, to change matching files in a hierarchy:

find . -name '*.txt' |xargs perl -pi -e 's/find/replace/g'

Comments on this post

jarnoan posts on Oct 03, 2007 at 09:32
That didn't work when the file names contained white space. This seems to work even with them (with GNU find and xargs):

find . -name '*.txt' -print0 |xargs -0 perl -pi -e 's/find/replace/g'


You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts