For example, you have a file or a variable containing several lines of text:

lines=”line one
line two
line three”

To append given string to the end of each line use sed:

$ sed -e 's/$/ ending/' <<<”$lines”
line one ending
line two ending
line three ending

To store it in a variable, use command substitution:

$ modified=$(sed -e 's/$/ ending/' <<<”$lines”)
$ echo “$modified”
line one ending
line two ending
line three ending

Of course, this can be done with files, too:

$ sed -e 's/$/ ending/' < myfile
line one ending
line two ending
line three ending

Leave a Reply

Close Menu