Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replace String on a Range of Lines Using the sed Command
#1

    Replace String on a Range of Lines Using the sed Command
   

Replace String on a Range of Lines Using the sed Command


   

Add the line numbers to the sed command to replace several strings within a specific range. Replace the first # with the initial text number and the second # with the last row you want to include.

   

Here’s the basic syntax:

   
sed '#,# s/old_string/new_string/' samplefile.txt
   

For example, the command below replaces the last three instances of “germany” located in the third, fourth, and fifth line on the countries.txt file, with the word “france”:

   
sed ‘3,5 s/germany/france/’ countries.txt
   

   
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)