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

后端 未结 4 755
萌比男神i
萌比男神i 2021-02-03 23:28

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         


        
4条回答
  •  悲哀的现实
    2021-02-04 00:06

    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.

提交回复
热议问题