I recently had the need to do some heavy search and replacement. I had to replace a simple string with a huge multi-line text. I was looking to sed, but perl can do this easily... I knew perl can do search and replace from the command line via the following: perl -pi -e 's/foo/bar/g' <files> And if you add something after the -i, it will make a copy before writing the new file: perl -p -i*.orig -e 's/foo/bar/g' <files> This will do the same as the first example, except it will copy the file first as filename.orig before doing the replacement. To take it one step further, and add in what my original question was, you have: perl -p -i*.orig -e 's/foo/`cat myfile`/eg' <files> Here, the /e runs eval on the inside of the s///, so `cat myfile` actually dumps the contents of my file inside there and replaces foo with it. And I tested it and if <myfile> spans multiple lines, it doesn't bother the perl one-liner one bit. I haven't test this one, but it seems logical that one can do the following: perl -p -i*.orig -e 's/`cat file1`/`cat file2`/eg' <files> To replace the contents of file1 with the contents of file2. Mmmm. Perl...........
