Awk 用于从两个不同文件中删除冗余行的脚本

Awk 用于从两个不同文件中删除冗余行的脚本,awk,pattern-matching,grep,Awk,Pattern Matching,Grep,我将用一个例子来解释我的问题 我在Solaris中有以下文件 文件1: 文件2: 现在我将file2作为参考,并打印file1 预期产出为: 3 INST N 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U385.A0 I have some text here 3 INST C 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U385.A1 I have some text here 3 INST C

我将用一个例子来解释我的问题

我在Solaris中有以下文件

文件1:

文件2:

现在我将
file2
作为参考,并打印
file1

预期产出为:

3 INST N 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U385.A0 I have some text here 
3 INST C 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U385.A1 I have some text here 
3 INST C 1 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U64.A1  I have some text here 
4 INST N 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U384.A0 I have some text here 
4 INST C 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U384.A1 I have some text here 
5 INST N 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U390.A0 I have some text here 
5 INST C 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U390.A1 I have some text here 
我已经尝试了
grep

grep -F -x -f file1 -v file2 > file3
fgrep -x -f file1 -v file2 > file3
fgrep

grep -F -x -f file1 -v file2 > file3
fgrep -x -f file1 -v file2 > file3
基于stackoverflow的几个帖子。但是我没有找到我需要的。因为我是一个新手,我真的很困惑如何找到一条出路。非常感谢您的帮助

这对您很有用:

grep -Ff file2 file1 >file3
使用您的文件进行测试:

kent$  grep -Ff f2 f1
3 INST N 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U385.A0 I have some text here
3 INST C 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U385.A1 I have some text here
3 INST C 1 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U64.A1 I have some text here
4 INST N 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U384.A0 I have some text here
4 INST C 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U384.A1 I have some text here
5 INST N 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U390.A0 I have some text here
5 INST C 0 top.gbp.stg1.stg2.stg3.stg4.stg5.stg6.stg6.U390.A1 I have some text here

您还可以帮助我如何将两个文件中不同的行作为输出吗?@CHEPTHA try
grep-vFf file2 file1>file3
如果这不符合您的要求,请发布一个新问题。