假设我有两个文件-file1.csv
和file2.csv
。我需要比较两个文件的第2列(字符串值),并打印出file2.csv
中的行,以获取file1.csv
的第3列中不存在的值。
我尝试使用以下awk
命令:
awk -F'\t''NR==FNR{c[$3]++;next};c[$3] == 0' file1.csv file2.csv
不过,这给了我所有的
file2.csv
。file2.csv
中只有两行多余的行不在file1.csv
中。有人能告诉我我做错了什么吗?
file1.csv
的片段(列从0开始编号)ANR 26545 CallExpression mutex_unlock ( & mmc_test_lock )
ANR 26546 Callee mutex_unlock
ANR 26547 Identifier mutex_unlock
ANR 26548 ArgumentList & mmc_test_lock
ANR 26549 Argument & mmc_test_lock
ANR 26550 UnaryOperationExpression & mmc_test_lock
ANR 26551 UnaryOperator &
ANR 26552 Identifier mmc_test_lock
ANR 26553 ExpressionStatement "__free_pages ( test -> highmem , BUFFER_ORDER )"
ANR 26554 CallExpression "__free_pages ( test -> highmem , BUFFER_ORDER )"
ANR 26555 Callee __free_pages
ANR 26556 Identifier __free_pages
ANR 26557 ArgumentList test -> highmem
ANR 26558 Argument test -> highmem
ANR 26559 PtrMemberAccess test -> highmem
ANR 26560 Identifier test
ANR 26561 Identifier highmem
ANR 26562 Argument BUFFER_ORDER
ANR 26563 Identifier BUFFER_ORDER
file2.csv
的片段ANR 12910 CallExpression mutex_unlock ( & mmc_test_lock )
ANR 12911 Callee mutex_unlock
ANR 12912 Identifier mutex_unlock
ANR 12913 ArgumentList & mmc_test_lock
ANR 12914 Argument & mmc_test_lock
ANR 12915 UnaryOperationExpression & mmc_test_lock
ANR 12916 UnaryOperator &
ANR 12917 Identifier mmc_test_lock
ANR 12918 IfStatement if ( test -> highmem )
ANR 12919 Condition test -> highmem
ANR 12920 PtrMemberAccess test -> highmem
ANR 12921 Identifier test
ANR 12922 Identifier highmem
ANR 12923 ExpressionStatement "__free_pages ( test -> highmem , BUFFER_ORDER )"
ANR 12924 CallExpression "__free_pages ( test -> highmem , BUFFER_ORDER )"
ANR 12925 Callee __free_pages
ANR 12926 Identifier __free_pages
ANR 12927 ArgumentList test -> highmem
ANR 12928 Argument test -> highmem
ANR 12929 PtrMemberAccess test -> highmem
ANR 12930 Identifier test
ANR 12931 Identifier highmem
ANR 12932 Argument BUFFER_ORDER
ANR 12933 Identifier BUFFER_ORDER
预期产量:
ANR 12918 IfStatement if ( test -> highmem )
ANR 12919 Condition test -> highmem
最佳答案
您需要将awk命令更改为:
awk -F'\t' 'NR==FNR {seen[$2]; next} !($2 in seen)' file1.csv file2.csv