In Linux, replacing all instances of a string with another string is easy thanks to sed
. A simple example is as follows:
To replace the string foo
with the string bar
in all .txt
files:
sed 's#foo#bar#g' *.txt
This will replace the strings. However, it won't actually save the changes and will instead output the modified text to the screen. To retain the changes or, in other words, to perform the replacements in place within the file, use the -i
switch:
sed -i 's#foo#bar#g' *.txt
Easy peasy Japanese.
- Log in to post comments