替换controlM字符或回车符并将下一行追加到上一行

时间:2015-07-24 18:54:03

标签: unix awk sed

我有一个像

这样的文件
"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"

我需要文件像

"A","b","HI This is Bad","End of line1"
"A","C","THIS is Good","End of line2"

我的文件毕竟还有一些垃圾数据。数据现在看起来像 -

"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.Cyrus给出的解决方案仅适用于1 ^ M.如果我有n ^ M怎么办,我怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

sed' / \ r $ / {:a; N; $!ba; s / \ r \ n / / g}' filename.csv> filename_final.csv

似乎有效。

基本上创建了一个标签并将其循环