My Board
Replace nth to All Occurrences with Sed - Printable Version

+- My Board (https://ellohost.com/forum)
+-- Forum: Tutoriel EN (https://ellohost.com/forum/forumdisplay.php?fid=8)
+--- Forum: Others (https://ellohost.com/forum/forumdisplay.php?fid=20)
+--- Thread: Replace nth to All Occurrences with Sed (/showthread.php?tid=718)



Replace nth to All Occurrences with Sed - aaron - 09-06-2023


    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