How can I add string to the end of the file without line break?
for example if i'm using >> it will add to the end of the file with line break:
cat list.txt
yourText1
root@host-37:/# echo yourText2 >> list.txt
root@host-37:/# cat list.txt
yourText1
yourText2
I would like to add yourText2 right after yourText1
root@host-37:/# cat list.txt
yourText1yourText2
If your sed implementation supports the -i option, you could use:
With the second solution you'll have a backup too (with first you'll need to do it manually).
Alternatively:
or
You can use the -n parameter of echo. Like this:
EDIT: Aha, you already had a file containing string and newline. Well, I'll leave this here anyway, might we useful for someone.
Just use
printf
instead, since it does not print the new line as default:Test
Let's create a file and then add an extra line without a trailing new line. Note I use
cat -vet
to see the new lines.The above answers didn't work for me. Posting a Python implementation in case anyone finds it useful.