AWK搜索字段在另一个文件 [英] awk search for a field in another file

查看:83
本文介绍了AWK搜索字段在另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在第二个文件一个文件搜索领域。不知道是否是AWK正确的解决方案。

i need to search for fields from one file in second file. Wondering if awk is right solution

文件1

one
two

文件2

something one
balh   one
blah two
blah two

所需的输出

one ["something one", "blah one"]
two [ "blah two" , "blah two"]

我希望我能够在AWK用awk着,寻找内的第二每一行,并构造输出。

i was hoping i could use awk with in awk , searching for each line within the second and constructing the output.

推荐答案

如果你愿意接受换取简单的解决方案略有不同的输出,那么grep的是您的工具:

If you are willing to accept a slightly different output in exchange for simpler solution, then grep is your tool:

grep -f file1 file2

在文件1每个令牌上面的命令搜索文件2。

The above command search file2 for every tokens in file1.

这篇关于AWK搜索字段在另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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