Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Does this answer your question? Relative line number in the range match in sed Commented May 14, 2021 at 2:07
  • @Quasímodo OK, but there end could be replaced with $, so for example seq 10|sed '/2/,${/2/,+5{/2/,+4!s/.*/replaceString/}}' from accepted answer or seq 10| sed '/2/{:a;N;$!ba;s/[^\n]*/replaceString/6}' from the second answer. no such big difference, but easy adjustable if one could understood how they works. BTW, I retracted my close vote. Commented May 14, 2021 at 5:00
  • 1
    Just use 10 lines of sample input/output instead of 500 and show us what the output should be if you want to print the 5th lines after every line that contains t. Different answers you have will give you the same output for two but different output for t. It would also be good if you showed if you want a regexp or string match. Commented May 14, 2021 at 13:33
  • 1
    Another edge case to consider - what if the string you're adding contained the string you're searching for, e.g. instead of MODIFIED it were fifty-two? Should THAT line then match with two and so you'd change the 5th line after THAT and every 5th line from then on? Commented May 14, 2021 at 13:47