从 CSV 中删除列

从 CSV 中删除列

我有一个 csv 文件,其格式为

input.csv

1,AREA,"POLYGON((103.855 1.27267,103.856 1.27316,103.851 1.27506,103.853 1.27941,103.853 1.2793,103.852 1.27879,103.852 1.27639,103.851 1.27624,103.851 1.27634,103.851 1.27661,103.851 1.27699,103.852 1.27985,103.852 1.28138,103.853 1.28188,103.853 1.28189,103.853 1.28058,103.853 1.28044,103.853 1.28048,103.853 1.28084,103.853 1.28206,103.853 1.28216,103.853 1.28205,103.853 1.28205,103.854 1.28196,103.854 1.28209,103.855 1.28141,103.855 1.2813,103.855 1.28086,103.856 1.28001,103.859 1.28528,103.859 1.28555,103.859 1.28556,103.859 1.28586,103.859 1.28587,103.859 1.28629,103.859 1.28662,103.859 1.28669,103.87 1.28157,103.873 1.27787,103.871 1.27586,103.863 1.26996,103.862 1.26924,103.861 1.2689,103.86 1.26869,103.859 1.26884,103.858 1.26921,103.856 1.2702,103.855 1.27088,103.856 1.27227,103.855 1.27253,103.851 1.27428,103.852 1.2739,103.855 1.27267))"

我想删除尺寸不固定的第三列。我尝试过

cut -d, -f3 --complement input.csv

但它工作不正常。感谢任何帮助。

答案1

cut工具不够智能,无法识别出第三列中的逗号不是分隔符。

不过,您可以选择一系列列:在本例中,-f1-2将选择第 1 列到第 2 列,从而排除第 3 列。

然而,对于一般的 CSV 处理,您需要更强大的解析器,例如 Python 和 Perl 等脚本语言中的解析器。

相关内容