awk脚本:检查来自一个文件的所有单词(字段)是否包含在另一个文件中 [英] awk script: check if all words(fields) from one file are contained in another file

查看:1174
本文介绍了awk脚本:检查来自一个文件的所有单词(字段)是否包含在另一个文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是awk脚本的新手。
我想通过字(字段)比较两个文件File1.txt和File2.txt做一个字段。
文件包含|的列表(管道)分隔字段。

I am new to awk scripting. I want to do a field by word (field) comparison of two files File1.txt and File2.txt. The files contain a list of | (pipe) separated field.

    File 1:
    -------------------
    aaa|bbb|ccc|eee|fff
    lll|mmm|nnn|ooo|ppp
    rrr|sss|ttt|uuu|vvv

    File 2: 
    -------------------
    aaa|bbb|ccc|eee|fff
    rrr|sss|ttt|uuu|vvv
    rrr|sss|ttt|uuu|uuu

同一行号。在这两个文件中。

We compare the same line no. in both the files.

两个文件匹配的第1行中的字段。

Fields in Line 1 of both file match.

在第2行中,所有字段(lll,mmm,nnn,ooo,ppp)不与所有字段(rrr,sss,ttt,uuu,vvv)文件2的第2行。类似地,两个文件中的第3行的第五字段(vvv,uuu)不匹配。

In Line 2 all the fields (lll, mmm, nnn, ooo, ppp) donot not match with all fields (rrr, sss, ttt, uuu, vvv) in line 2 of File 2. Similarly the 5th field (vvv, uuu) of 3rd line in both the files donot match.

因此行号。 2和行号。 3应该被bash回调。

Hence Line no. 2 and Line no. 3 should get echoed by bash.

这两个文件都将遵循一个顺序。

Both files will follow an order.

推荐答案

此行应该执行:

awk 'NR==FNR{a[FNR]=$0;next}a[FNR]!=$0' file1 file2

输出:

rrr|sss|ttt|uuu|vvv
rrr|sss|ttt|uuu|uuu

这篇关于awk脚本:检查来自一个文件的所有单词(字段)是否包含在另一个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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