使用echo和猫不需要的换行符 [英] Unwanted line break using echo and cat
本文介绍了使用echo和猫不需要的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在文件的开头添加一条线,用
I'm trying to add a line at the beginning of a file, using
echo 'time/F:x1:x2' | cat - file.txt>newfile.txt
但是,这会产生换行符在新文件中的每一行(除了增加了时间/ F:X1:X2'后线)。如何避免这种情况的任何想法?
But this produces line breaks at each line in the new file (except for after the added 'time/F:x1:x2' line). Any ideas on how to avoid this?
推荐答案
使用 -n
来禁用尾随的换行符:
Use -n
to disable the trailing newline:
echo -n 'time/F:x1:x2' | cat - file.txt > newfile.txt
有其他的方法,也:
sed '1s|^|time/F:x1:x2|' file.txt > newfile.txt
这篇关于使用echo和猫不需要的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文