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

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

    The above answers didn't work for me. Posting a Python implementation in case anyone finds it useful.

    python -c "txtfile = '/my/file.txt' ; f = open(txtfile, 'r') ; d = f.read().strip() ; f.close() ; d = d + 'the data to append' ; open(txtfile, 'w').write(d)"
    

提交回复
热议问题