35

I have a line that says...

Fred Flintstone, Bedrock USA

and I want it to look like...

Fred Flintstone, Bedrock USA ***

How do I append a few * to the end of the line using sed command?

αғsнιη
  • 35,660
Justin
  • 2,121

1 Answers1

49

You can use this:

sed 's/$/ ***/' filename

If you want to search for a specific string before appending to a line (that is you don't want it appended to EVERY line like the above command) you can use the following, this finds Fred Flintstone anywhere in a line, put^ in front if you only want to match the beginning of the line.

sed '/Fred Flintstone/ s/$/ ***/' filename
dragon788
  • 1,556
Cyrus
  • 5,554
  • 1
    That worked perfectly! How do you use it to append to a certain line? The above command does it for every line in the text file. I'm interested in making in work for all lines that start with the name "Fred" – Justin Oct 16 '14 at 20:49
  • 5
    @Justin: sed 's/^Fred.*/& ***/' filename – Cyrus Oct 16 '14 at 20:53
  • @heemayl: "The replacement may contain the special character & to refer to that portion of the pattern space which matched" -- from man bash – Cyrus Oct 16 '14 at 20:54