in reply to Searching and Replacing file content within directory

Can you use sed? It can make replacements in-line and search recursively through the directories.
  • Comment on Re: Searching and Replacing file content within directory

Replies are listed 'Best First'.
Re^2: Searching and Replacing file content within directory
by stevemayes (Scribe) on Nov 12, 2010 at 15:34 UTC
    I love perl yet often I'll see an issue like this and think 'replace that with a small shell script' or in this case do it all with sed. Glad I'm not the only one. :)

      sed? I prefer to stick with perl. Here's a 1-liner to search and replace:

      perl -i -wpe 's/INPUT_TXT/OUTPUT_TXT/g' file1 [... fileN]

      See the perlrun docs for info on using -i.

      Use find if needed to generate the list of files, and pipe its output to Perl via xargs.