Using sed you can easily change text in multiple files, eg:
sed -i 's/cashtestUS/cheque_usd/g' *.xml
The problem is that this has tremendous power, and a complex regular expression could easily have unforeseen consequences.
Is there a simple way to do either:
1) Echo the changes made
2) Run sed in a preview mode, so that the potential changes can be previewed
There is a huge pool of commands available for Ubuntu and sed command utility is one of them; the sed command can be used to perform fundamental operations on text files like editing, deleting text inside a file.
The sed command has longlist of supported operations that can be performed to ease the process of editing text files. It allows the users to apply the expressions that are usually used in programming languages; one of the core supported expressions is Regular Expression (regex).
Both sed and awk allow processing streams of characters for tasks such as text transformation. The awk is more powerful and robust than sed. It is similar to a programming language.
Run in preview mode without the -i
:
sed -e 's/cashtestUS/cheque_usd/g' *.xml
(The -e
is not necessary; it just says the next argument is the sed
script, or one part of the sed
script.) This writes all the output to standard output. You'd probably pipe it through less
(or more
), or pass it through grep
to see that the changed lines were those you expected. Or you might process one file at a time and run a difference:
for file in *.xml
do
echo "$file"
sed -e 's/cashtestUS/cheque_usd/g' "$file" | diff -u "$file" -
done
Or …
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With