Let's say we want to replace the letter "a" with its Morse code equivalent from a text.txt file to a hidden .out.txt file using sed, with the contents of the original file being "this is a test".
#!/bin/bash
touch .out.txt
cat text.txt > .out.txt
sed 's/a/.-/g' .out.txt
The output, as expected, is "this is .- test".
However, let's say we want to do multiple instances of sed, without constantly printing the result of each instance of sed using the -n parameter. In this case:
#!/bin/bash
touch .out.txt
cat text.txt > .out.txt
sed -n 's/a/.-/g' .out.txt
sed -n 's/t/-/g' .out.txt
cat .out.txt
However, in this case, the output of cat is the same as the contents of text.txt, "this is a test".
Is there a possible substitute for -n
, or in general a way to prevent sed from printing anything with our wanted result?