If I have this document
aaa
bbb
ccc
And I want to add " ddd" on the last line. My document should look like this:
aaa
bbb
ccc ddd
How can I do this? If I prefer awk or sed but i'm open to your proposals. Thanks
If I have this document
aaa
bbb
ccc
And I want to add " ddd" on the last line. My document should look like this:
aaa
bbb
ccc ddd
How can I do this? If I prefer awk or sed but i'm open to your proposals. Thanks
In this case sed
is the simplest. To add text to the last line of file f
:
sed '$s/$/ ddd/' f
To append contents of a file ff
after the last line of file f
, one of:
sed '$r ff' f
cat ff >> f
To append contents of a file ff
(with only one line of data) to the last line of file f
:
sed '$s/$/ '$(< ff)'/' f
cat sed '$s/$/ '$(< ff)'/' f >> fff
instead.
– Janis
Mar 26 '15 at 18:37
cat
from my previous comment (I copied it from your code without noticing).
– Janis
Mar 26 '15 at 22:17