Unix脚本在每行末尾附加^ M [英] Unix script appends ^M at end of each line
本文介绍了Unix脚本在每行末尾附加^ M的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个执行以下操作的Unix shell脚本:
I have a Unix shell script which does the following:
- 创建文件备份
- 在文件中添加一些文本
现在在#2中,如果我插入文本,^ M将附加在文件的所有行上.
Now in #2 if I insert a text, ^M gets appended on all the lines of the file.
例如:
echo " a" >> /cust/vivek.txt
echo " b" >> /cust/vivek.txt
vi vivek.txt
abc^M
bcd^M
a^M
b^M
有什么办法可以避免这种情况?
Any way to avoid this?
推荐答案
我不确定 echo
如何产生 ^ M
个字符,但是您可以通过以下方式将其删除在文件上运行 dos2unix
,如下所示:
I'm not sure how echo
could be producing ^M
characters but you can remove them by running dos2unix
on your file, like this:
dos2unix /cust/vivek.txt
这篇关于Unix脚本在每行末尾附加^ M的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文