Run sed over multiple files

To run a sed command over multiple files in a directory.

eg. htm files in a dir and output the changed files to a subdirectory called output/ use:

ls -1 *.htm | { while read i; do sed -f modify.sed $i >  output/$i; done }

This pipes the output of a single column ls command of *.htm files to a while loop that acts on each line of the ls output.

Each iteration of the loop runs the sed command using the modify.sed file that contains the modification commands.

The output of the sed command is redirected to the same filename as the input file but in a subdirectory called output/.

Back to GNU/Linux Command Line Tips