[Lubuntu] Sed substitution with partially duplicate results

Jonathan Marsden jmarsden at fastmail.fm
Wed Dec 19 22:27:10 UTC 2012


John,

On 12/19/2012 01:16 PM, John Hupp wrote:

>>> It all works fine except for this substitution:
>>> -e 's/DEVICE/DEVICE Lubuntu1:3551/'

If the original line concerned starts out as just DEVICE (followed by a
line feed to mark the end of line), then I'd suggest making the sed
command be

  sed -e 's/DEVICE$/DEVICE Lubuntu1:5551/'

So that, even if run twice, the second run will have no effect on this line.

If there *is* "other junk" after DEVICE before the end of the line, and
there is only one line containing DEVICE in the file concerned, you
could consider

  sed -e 's/DEVICE.*$/DEVICE Lubuntu1:3551/'

which would remove any trailing junk after DEVICE and replace it with
the desired string.

Jonathan




More information about the Lubuntu-users mailing list