Ah yes, time for a perl oneliner. How about this?
perl -pi -e 's/old text/new text/' file
or maybe you want to change all the *.txt files in the current directory? In that case, how about combining it with GNU parallel:
parallel perl -i.bak -pe 's/foo/bar/' ::: *.txt
With parallel, the :::
means use eveything after this as input files.
or, to change all the txt files in the current directory and below:
find . -name \*txt -print0 | parallel -q -0 perl -i.bak -pe 's/old text/new text/'
Note the -i.bak
saves a backup copy of every file that you change, in case you make a mistake. You can leave that out if you are feeling dangerous.
Anyway obviously the sed
answer is the standard one, but there are some fun alternative ways to do it too. Also if you have a lot of files gnu parallel will be significantly faster as it runs multiple copies in parallel (as one would hope, given the name).