我有一个带有数字和字符串值的 .CSV 文件(比如说命名为 file.csv)。该字符串可能包含逗号,因此它们用双引号括起来,如下所示。
column1,column2,column3,column4,column5,column6,column7
12,455,"string, with, quotes, and with, commas, in between",4432,6787,890,88
4432,6787,"another, string, with, quotes, and, with, multiple, commaz, in between",890,88,12,455
11,22,"simple, string",77,777,333,22
当我尝试在文件末尾添加空列时,使用以下代码
awk -F, '{NF=13}1' OFS="," file.csv > temp_file.csv
输出不符合我的要求。该代码还计算了文本限定符字段中的逗号,它们用双引号括起来。使用上述命令的文件输出cat temp_file.csv
如下:
column1,column2,column3,column4,column5,column6,column7,,,,,,
12,455,"string, with, quotes, and with, commas, in between",4432,6787,890,88,
4432,6787,"another, string, with, quotes, and, with, multiple, commaz, in between",890,88
11,22,"simple, string",77,777,333,22,,,,,
因为我需要该字段中的字段总数为 13。非常感谢使用awk
或使用任何关于此问题的输入。sed