我不擅長unix。如何在Unix中用~~替換新行和^ M字符
我有一個csv文件,我有多個列。其中,一列包含新行和^M
字符。我需要~~
全部更換它們兩個之間「(這是一種單細胞值),這樣我可以把單元格的值作爲單場下面是示例文件:
"id","notes"
"N001","this is^M
test.
Again test
"
"N002","this is perfect"
"N00345","this is
having ^M
problem"
我需要這個文件中像:
"id","notes"
"N001","this is~~test.~~~~Again test~~~~"
"N002","this is perfect"
"N00345","this is~~~~having ~~problem"
使整個單元格值可以理解爲一個單一的字段值
我要在此要求,其中一個單元格中的數據包含"
(雙引號)添加更多的情況在這裏。在這種情況下,我們可以識別endin g "
,後面跟着逗號。以下是更新的情況下數據:
"id","notes"
"N001","this is^M
test. "Again test."
Again test
"
"N002","this is perfect"
"N00345","this is
having ^M
problem as it contains "
test"
我們可以保持"
或刪除它。預期的輸出是:
"id","notes"
"N001","this is~~test. "Again test."~~~~Again test~~~~"
"N002","this is perfect"
"N00345","this is ~~~~having ~~problem as it contains "~~test"
嗨,你的sed命令工作完美我猜。但是它在控制檯評估者上輸出的結果要比保存在同一個文件中。我使用-i選項嗎?請回復。非常感謝。 – user3021141
@ user3021141是的,您需要使用'-i'選項進行就地替換。更新了我的答案。 – jkshah
+1 for dos2unix – Mathew