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

后端 未结 4 749
萌比男神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:03

    Just use printf instead, since it does not print the new line as default:

    printf "final line" >> file
    

    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.

    $ seq 2 > file
    $ cat -vet file
    1$
    2$
    $ printf "the end" >> file
    $ cat -vet file
    1$
    2$
    the end
    

提交回复
热议问题