is it possible to change multiply patterns to different values at the same command? lets say I have
A B C D ABC
and I want to change every A to 1 every B to 2 and every C to 3
so the output will be
1 2 3 D 123
since I have 3 patterns to change I would like to avoid substitute them separately. I thought there would be something like
sed -r s/'(A|B|C)'/(1|2|3)/
but of course this just replace A or B or C to (1|2|3). I should just mention that my real patterns are more complicated than that...
thank you!
sed 's/A/1/g;s/B/2/g;s/C/3/g' file? - anubhavatr 'ABC' '123'- user4453924s///especially on complex pattern like @anubhava ask ? - NeronLeVelutr) and the right way to handle "words" really depends on what a "word" means to you and/or what the separators can be between the "words". As written right now your question is extremely likely to produce a solution that works for your posted input but will fail (possibly quietly and/or cryptically and/or disastrously) later when run against some different input. - Ed Morton