Ocasta Eshu
Ocasta Eshu

Reputation: 851

how to append to an existing line using sed

I would like to output a file's contents appended with a string without creating a new line.

so far my command places the appended string on a new line:

sed -e 'a foo' file.txt
>> file contents...
>> foo

I want the output to look like this:

>> file contents...foo

Upvotes: 3

Views: 7794

Answers (1)

Gilles Quénot
Gilles Quénot

Reputation: 185790

With sed (tested successfully on Archlinux & Minix):

sed '$s/$/foo/' file.txt

$ at the beginning, mean end of file.

If you need to add foo on each lines :

sed 's/$/foo/' file.txt

In the latest context, $ mean end of line

Upvotes: 6

Related Questions