Regex 包含一些相同字符串的2个文件

Regex 包含一些相同字符串的2个文件,regex,linux,text,awk,grep,Regex,Linux,Text,Awk,Grep,我有两个文件 文件1: 012:coffee 013:salt 014:apple 015:mushrooms 016:tree 文件2: Subject: Three tips to get the most out of Gmail Subject: The best of Gmail, wherever you are Subject: Stay more organized with Gmail's inbox Subject: 012 Subject: 014 如何生成一个新文件来

我有两个文件

文件1:

012:coffee
013:salt
014:apple
015:mushrooms
016:tree
文件2:

Subject: Three tips to get the most out of Gmail
Subject: The best of Gmail, wherever you are
Subject: Stay more organized with Gmail's inbox
Subject: 012
Subject: 014
如何生成一个新文件来比较前两个文件并包含:

012:coffee
014:apple
如果文件2中的主题文本包含冒号,则需要使用子方法,而不是依赖$2。

使用单个awk命令:

输出:

012:coffee
014:apple

这个问题并不完全清楚。你在什么基础上试图获得输出?请使用更多详细信息更新问题Stack Overflow不是代码编写服务。请出示你的密码。因为堆栈溢出对您隐藏了关闭的原因:寻求调试帮助的问题为什么这段代码不起作用?必须包括所需的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:。
awk -F':[[:space:]]*' 'NR==FNR{ if($2 ~ /^[0-9]+$/) a[$2]; next }$1 in a' file2 file1
012:coffee
014:apple