更换controlM字符或回车符和下一行追加到previous线 [英] Replace controlM character or a carriage return character and append the next line to previous line
本文介绍了更换controlM字符或回车符和下一行追加到previous线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有像
"A","b","HI This is Bad","End of line1" -- This line1 is good
"A","C","THIS is^M ------THis line2 is bad.
Good","End of line2"
我需要的文件,像
I need the file to be like
"A","b","HI This is Bad","End of line1"
"A","C","THIS is Good","End of line2"
我的文件有更多一点的垃圾数据毕竟。现在的数据看起来像 -
My file has a little more junk data after all. The data now looks like -
"A","b","HI This is Bad","End of line1" -- This line1 is good
"A","C","THIS is^M ------THis line2 is bad.
Goo^M
d","End of line2"
因此,认为像上面可能有多个^ M,而不仅仅是1或2赛勒斯给出的解决方案,适用于只有1 ^ M。如果我有n个^ M,我怎么能解决这个问题?
So think like above might have multiple ^M rather than just 1 or 2. The solution given by Cyrus, works for only 1 ^M. What if I have n ^M, how can I resolve this?
推荐答案
sed的'/ \\ R $ / {:一; N; $ BA; S / \\ r \\ n / / G}'filename.csv> filename_final的.csv
sed '/\r$/{:a;N;$!ba;s/\r\n/ /g}' filename.csv>filename_final.csv
似乎已经奏效。
基本上创建了一个标签,它循环
Basically created a label and looped it
这篇关于更换controlM字符或回车符和下一行追加到previous线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文