Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replace nth to All Occurrences with Sed
#1

    Replace nth to All Occurrences with Sed
   

Replace nth to All Occurrences with Sed


   

Use sed to replace patterns from the nth to all occurrences in a line:

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

For example, to replace "pisces" with "aquarius" from the second occurrence to all occurrences:

   
sed 's/pisces/aquarius/2g' astrology.txt
   

   
Reply


Messages In This Thread
Replace nth to All Occurrences with Sed - by aaron - 09-06-2023, 11:21 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)