Unix finds and replaces characters with multiple character strings

I want to replace all occurrences of certain characters in my file with words. My question is: can I do this for all characters using one command. I use the following command to replace each occurrence of "a" with "apples"

sed 's/a/apple/g' sample.txt 

I do not want to write 3 or 4 similar commands to replace each occurrence of "b", "c", "d" with a few words. Is there any way to expand the above command according to my need or do I need to use the same three times?

+4
source share
1 answer

You can use the -e switch in sed to enter several commands, such as:

 sed -i.bak -e 's/a/apple/g' -e 's/b/bat/g' -e 's/c/cat/g' 
+3
source

Source: https://habr.com/ru/post/1482079/


All Articles