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.

10
  • 2
    OP asks for replace 2nd occurrence, not first occurrence on 2nd line. Commented May 20, 2020 at 15:55
  • @pLumo why not? This is exactly what the OP is asking for, isn't it? This will replace the word line on the second line. It produces the same output as your -z approach but is more portable and doesn't require reading the entire file as a single line. Commented May 20, 2020 at 15:59
  • 1
    It does the same for that piece of text, but it is till not what OP is asking for. Especially considering "I am learning sed". Commented May 20, 2020 at 16:00
  • @pLumo I guess it depends on how you read the question. I read it as the OP misunderstanding what the /2 does, since they clearly expected it to make the change on the second line. Good to have both approaches, anyway. Commented May 20, 2020 at 16:01
  • 1
    I disagree with "he clearly wanted the change to occur on the second line", but as @terdon has said: "Good to have both approaches" ;-) Commented May 20, 2020 at 16:18