您好我有一个文本csv文件,其中一些行被“破坏”如下:
blahblahblah;"- lalalal
- lolololo
- lililili";
我尝试了以下命令,但没有任何改变。
sed -i -e 's/\n-//g' sample.txt
sed ':a;N;$!ba;s/\n-/ /g' sample.txt
正确的行应如下所示:
blahblahblah;"- lalalal - lolololo - lililili";
它是带有Windows EOF格式的ANSI文本文件。也许这就是问题?
答案 0 :(得分:0)
kent$ echo 'blahblahblah;"- lalalal
- lolololo
- lililili";'|awk '{printf "%s",$0}END{print ""}'
blahblahblah;"- lalalal- lolololo- lililili";
或设置ORS
:
kent$ echo 'blahblahblah;"- lalalal
- lolololo
- lililili";'|awk -v ORS="" '7;END{print "\n"}'
blahblahblah;"- lalalal- lolololo- lililili";
修改强>(GAWK)
然后你给出了一个糟糕的例子。无论如何,正如你所要求的那样:kent$ echo 'blahblahblah;"- lalalal
- lolololo
- lililili";'|awk -v RS='\0' -v ORS="" '{gsub(/\n-/,"-")}7'
blahblahblah;"- lalalal- lolololo- lililili";
如果下一个字符为\n
-
答案 1 :(得分:0)
使用gnu awk
即可:
awk '{gsub(/\n-/, "-", $0); print $0}' RS=';\n' file
blahblahblah;"- lalalal- lolololo- lililili"
答案 2 :(得分:0)
gsed ':a;N;$!ba;s/\n-/ -/g' sample.txt
blahblahblah;"- lalalal - lolololo - lililili";