【发布时间】:2013-12-07 03:59:51
【问题描述】:
我不擅长unix。
我有一个 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"
这样整个单元格的值可以作为单个字段值读取。
我需要在此要求中再添加一个案例,其中单元格中的数据包含"(双引号)。在这种情况下,我们可以识别结尾 " 后跟逗号。以下是更新的案例数据:
"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"
【问题讨论】:
标签: file unix replace sed newline