-1

Is there an example of if you want to replace multi-words with one word

for example input: dog apple orange banana pear output dog cat cat banana cat

I have solved with this below is there is a better way(better than sed)? by not typing cat three times:

sed -e 's/apple/cat/g;s/orange/cat/g;s/pear/cat/g'

thanks in advance

Sinto
  • 3,915
  • 11
  • 36
  • 70

1 Answers1

0

Simply replace the strings at once using OR operator

sed -e 's/apple\|orange\|pear/cat/g' filename
Amit Bhardwaj
  • 333
  • 1
  • 8