如何用awk删除其中matche其他CSV列一列从一个CSV行,一些值? [英] How to use awk to delete rows from one csv, some values in a column of which matche the other csv column?

查看:331
本文介绍了如何用awk删除其中matche其他CSV列一列从一个CSV行,一些值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图从CSV其中在特定的列项中的其他CSV匹配项删除行(记录)。

I have been trying to delete rows (records) from a csv in which entries in a specific column match the entries in the other csv.

该CSV结构大致是这样的:

The csv structure is roughly like this:

1.csv

Col1,Col2,Col3,Col4,Col5
sasdf,3432,fjkdk,fjjof,1234
efvr,4565,fhjs,dihi,9999
asa,234,rgs,fkjf,0102
aaa,456,jfvv,dofh,4565
ths,7865,fhjf,fhks,3212

2.csv

Col1    
1234
3212    
0102
4565

因此​​,大家可以看到,有在1.csv的COL5出现在2.csv的COL1一些值
我想用awk删除1.csv匹配2.csv的COL1的行(记录)

So as you can see, there are some values in col5 of 1.csv that appear in col1 of 2.csv I want to use awk to delete the rows (records) from 1.csv that match col1 of 2.csv

所以输出应该是这样的:

So the output would look like this:

3.csv

Col1,Col2,Col3,Col4,Col5
efvr,4565,fhjs,dihi,9999

下面是我使用的awk脚本:

Here is the awk script I used:

awk -F"," 'NR==FNR{array1[FNR]=$1};NR>FNR{array1[FNR]!~$5}' 2.csv 1.csv > 3.csv

它没有工作。

推荐答案

这将这样的伎俩:

$ awk -F, 'NR==FNR{a[$1];next}!($5 in a)' 2.csv 1.csv
Col1,Col2,Col3,Col4,Col5
efvr,4565,fhjs,dihi,9999

$ awk -F, 'NR==FNR{a[$1];next}!($5 in a)' 2.csv 1.csv > 3.csv

这篇关于如何用awk删除其中matche其他CSV列一列从一个CSV行,一些值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆