09-08-2023, 11:56 AM
Duplicate the Replaced Line With /p Flag Using the sed Command
To duplicate the replaced line on the terminal window, use the /p or print flag. However, if the line doesn’t have the search pattern and is not substituted, the command only outputs it once.
Here’s the general syntax:
sed 's/old_string/new_string/p' samplefile.txt
For example, to replace the word "phones" with "tablets" on the gadgets.txt file and duplicate the results on the terminal window, run:
sed 's/phones/tablets/p' gadgets.txt

