删除少于 7 列且第二列为空的行
Deleting rows with less of 7 columns and with an empty second column
我需要从 csv 中删除所有少于 7 个字段的行以及第二列为空的行
V8, 5,2015-01-14,3.7,-0.8,0.2,7.2
CT,,,,,,
R1, 6,2015-01-14,9.7,-1.0,0.0,14.4
Z8, 5 ,2015-01-14,1.4,-4.0,0.1,54.4
XL, 5,2015-01-14,15.0,6.4,0.0,27.7
D9, 6,2015-01-14,16.4,2.6,0.0,34.6
XM, 6,2015-01-14,2.2,-0.2,0.2,9.0
ZC, 5 ,2015-01-14,
,
,
我有 7 个字段(列)
awk -F',' '{print NF; exit}' 2015-01-14.csv
7
我尝试了下一个命令来删除少于 7 fields/columns 的行,但 运行
awk -F"," 'NF>=7' 2015-01-14.csv
有什么帮助吗?
你可以试试下面的方法,
$ awk -F, 'NF>=7 && != ""' file
V8, 5,2015-01-14,3.7,-0.8,0.2,7.2
R1, 6,2015-01-14,9.7,-1.0,0.0,14.4
Z8, 5 ,2015-01-14,1.4,-4.0,0.1,54.4
XL, 5,2015-01-14,15.0,6.4,0.0,27.7
D9, 6,2015-01-14,16.4,2.6,0.0,34.6
XM, 6,2015-01-14,2.2,-0.2,0.2,9.0
这将打印具有 7 个或更多字段的行,并且第二个字段不会为空。
我需要从 csv 中删除所有少于 7 个字段的行以及第二列为空的行
V8, 5,2015-01-14,3.7,-0.8,0.2,7.2
CT,,,,,,
R1, 6,2015-01-14,9.7,-1.0,0.0,14.4
Z8, 5 ,2015-01-14,1.4,-4.0,0.1,54.4
XL, 5,2015-01-14,15.0,6.4,0.0,27.7
D9, 6,2015-01-14,16.4,2.6,0.0,34.6
XM, 6,2015-01-14,2.2,-0.2,0.2,9.0
ZC, 5 ,2015-01-14,
,
,
我有 7 个字段(列)
awk -F',' '{print NF; exit}' 2015-01-14.csv
7
我尝试了下一个命令来删除少于 7 fields/columns 的行,但 运行
awk -F"," 'NF>=7' 2015-01-14.csv
有什么帮助吗?
你可以试试下面的方法,
$ awk -F, 'NF>=7 && != ""' file
V8, 5,2015-01-14,3.7,-0.8,0.2,7.2
R1, 6,2015-01-14,9.7,-1.0,0.0,14.4
Z8, 5 ,2015-01-14,1.4,-4.0,0.1,54.4
XL, 5,2015-01-14,15.0,6.4,0.0,27.7
D9, 6,2015-01-14,16.4,2.6,0.0,34.6
XM, 6,2015-01-14,2.2,-0.2,0.2,9.0
这将打印具有 7 个或更多字段的行,并且第二个字段不会为空。