Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Duplicate the Replaced Line With /p Flag Using the sed Command
#1

    Duplicate the Replaced Line With /p Flag Using the sed Command
   

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
   

   
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)