I need a tool that can open a text file and replace characters in a list with other characters in a list.
For example:
Lets say I have a list of "aA", "aB", and want to replace "aA" with "AA".
What is a software program that could do this easily?
I need a tool that can open a text file and replace characters in a list with other characters in a list.
For example:
Lets say I have a list of "aA", "aB", and want to replace "aA" with "AA".
What is a software program that could do this easily?
This is exactly what the sed
program was made for.
ex
. Or indeed tr
if using sed
to change case is seen as hard (which, with GNU sed
at least, it really isn't).
As a Perl one-liner, to replicate sed functionality...
perl -pe " s/aA/AA/g; s/aB/AB/g; " < input.txt > output.txt
This will turn this input.txt...
aA, aA, aA, aA, aA
aB, aB, aB, aB, aB
into this output.txt...
AA, AA, AA, AA, AA
AB, AB, AB, AB, AB
It does this through regular expression substitution...
s(ubstitute)/this-original-string/with-this-new-string/g(lobally)