我有以下CSV文件:
"test","test2","test
3 and some other
data"
"test4","test5","test6 and some other
data"
我想用字符
\n
替换所有换行符(windows或unix样式),这样我将获得:"test","test2","test\n3 and some other\n\ndata"
"test4","test5","test6 and some other\n\n\ndata"
我尝试过
awk
但没有成功:cat myFile.csv | awk -F \" -v OFS=\" '{
for (i=0; i<NF; i++) {
gsub("\\n", "\\\\n", $i)
}
print
}'
最佳答案
有一种方法:
$ awk '!/"$/{sub(/$/,"\\n");printf "%s",$0;next}1' file
"test","test2","test\n3 and some other\n\ndata"
"test4","test5","test6 and some other\n\n\ndata"
关于bash - bash将换行符替换为引号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16036744/