Well, in this case, the suggestions given by Magic Banana work well together with mine. ;)
The extra line that you said gets inserted is because you forgot `-n', if you absolutely don't want `-n', then remove the `p' flag from the `s' command. 2017-11-27T18:18:36-0600 Caleb Herbert wrote: > Your suggestion does not add to the lines. It deletes them entirely. > > <code> > cal@leela:~$ sed 's/^x .*\(.\)$/CHARIZARD/gp' "file.txt" > c ^x a1 > y b2 > z c3 > b x d4 > y e5 > z f6 > CHARIZARD > CHARIZARD > a ^x > y > z > e ^x > x > d qwerty ^x azerty aBc > </code> > > Also, it matches incorrectly. > > * An extra CHARIZARD line was inserted > * "x " at the beginning of the penultimate line was NOT matched > > My intended result is to ADD text to the end of any lines that start > with "x ". > > <code> > c ^x a1 > y b2 > z c3 > b x d4 > y e5 > z f6 > x abC W-CHARIZARD > a ^x > y > z > e ^x > x CHARIZARD > d qwerty ^x azerty aBc > </code>
