HISPACTA Hell

Thursday, July 09, 2009

Command line find & replace

Thanks to http://schestowitz.com/Software/Search_and_Replace/, I re-remebered how to find and replace across a suite of files (either recursively or just within a directory).


find . -maxdepth 1 -type f -name '*.html' -print |
while read filename
do
(
sed 's/old/new/i;' $filename >$filename.xxxxx
mv $filename.xxxxx $filename # replace output files with original
)
done


You can rock it with just an "ls" instead of a "find", etc.

So for example I help Anh out by changing a ton of YAML test case definition files that needed updating after a big schema change:

ls |
while read filename;
do (
sed 's/pdf_document/document_path/g;' $filename >$filename.xxx;
mv $filename.xxx $filename;
)
done

0 Comments:

Post a Comment

<< Home