This week, after refactoring some XML based Java classes, I was left with ~50 XML documents (used for testing) with the wrong root element. After a few seconds pondering opening a text editor and find/replacing 50 times I had a better idea: sed.

sed can be used to perform regular expressions on each line of a file (or files). To solve the problem all it took was:

sed -i s/oldroot/newroot/ *

-i: edits the files in place instead of printing to stdout

All 50 documents updated, simple as that.