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*

9
  • It's unclear how you want to use the line numbers. Appending something to each line that contains pants can be done with sed '/pants/ s/$/WORD/'. Commented Jan 24, 2022 at 10:30
  • I only want to append WORD on line 6 and not every line which containts the word "pants". Commented Jan 24, 2022 at 10:32
  • Please edit your question to add requested information or clarification. Please also add more details in what way it "is not working". Commented Jan 24, 2022 at 10:37
  • 1
    If the input line was sweatpants are comfortable and the line number was a match should WORD be added to the end of that line? i.e. do you want to match on partial words or only full words? Commented Jan 25, 2022 at 13:26
  • 1
    OK - all of the answers posted so far, including the one you accepted, do partial word matches instead of full word and so will fail given the case I mentioned. You should update your sample input/output (or maybe more appropriately ask a new question) to cover that case and any others you can think of so we have something to test a potential solution against. With these sorts of questions it's always trivial to match the text you want but harder to not match similar text you don't want so it's very important when asking such a question to really THINK about the possible input. Commented Jan 25, 2022 at 14:06