Bash: performing multiple substitutions with a single sed invocation

Instead of stringing together sed multiple times in a pipeline, it is also possible to make multiple substitutions with a single invocation of sed.

Consider the following example which replaces the word ‘hello’ as well as ‘quick’ in the paragraph:

$ sed "s/hello/goodbye/g; s/quick/slow/g" <<EOF
hello, world!
hello, universe!
the quick brown fox
EOF

goodbye, world!
goodbye, universe!
the slow brown fox

The semicolon is the separator of the sed commands.

test_chain_sed.sh available on github.

REFERENCES

sed reference