Shell Appending string to last line of file.

For what it's worth, it works for me.

Code:
cat somefile
this is a
file.
sed '$s/$/ EOF/' somefile 
this is a
file. EOF

There is also gsed, which works as it would in Linux, and can be installed with
Code:
pkg install gsed
I use it sometimes when I'm lazy and don't feel like editing someone's Linux script.
For example, in FreeBSD, to edit a file in place it's sed -i ""' whereas with gsed, it's just sed -i.
 
For what it's worth, it works for me.

Just tried it with another file and it works just as it should, but I just noticed the file I was trying it with ended with the string ${1+"$@"}
which may well have resulted unexpected results.

What does this do?

sed '$s/$/ EOF/' /usr/local/bin/chrome
 
Bash:
ed filename << 'EOT'
a
Hello world!
.
-,.j
w
EOT
Enter append mode, the text you want to append, finish entering with a single . on a line, join the previous line with the current line, and write the buffer to disk. NB: Addressing the previous line will fail if the original file does not contain any line.​
 
Back
Top