Bash: add string to the end of the file without line break

Crazy_Bash picture Crazy_Bash · Jan 5, 2012 · Viewed 53.4k times · Source

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

Answer

Franz picture Franz · Jan 5, 2012

You can use the -n parameter of echo. Like this:

$ touch a.txt
$ echo -n "A" >> a.txt
$ echo -n "B" >> a.txt
$ echo -n "C" >> a.txt
$ cat a.txt
ABC

EDIT: Aha, you already had a file containing string and newline. Well, I'll leave this here anyway, might we useful for someone.