awk打印两个文件之间找不到的行

时间:2017-05-19 12:37:52

标签: awk

在下面的awk中,我正在尝试打印file2中不在$2 $3file1之间的那些行。我认为它很接近,但目前正在打印出比赛。基本上,与它正在做的相反。

awk with current output

awk '
NR==FNR{for(i=$2;i<=$3;++i) d[$1,i] = $6; next}
d[$1,$2]{print $0}' file2 file1
chr1 948953 948956 chr1:948953-948956 . ISG15
chr1 949363 949858 chr1:949363-949858 . ISG15
chr19 42373737 42373856 chr19:42373737-42373856 . RPS19

文件1

chr1 948953 948956 chr1:948953-948956 . ISG15
chr1 949363 949858 chr1:949363-949858 . ISG15
chr19 42373737 42373856 chr19:42373737-42373856 . RPS19

file2的

chr1 948796 949006 chr1:948796-949006 . ISG15
chr1 949313 949969 chr1:949313-949969 . ISG15
chr19 42363937 42364409 chr19:42363937-42364409 . RPS19
chr19 42364286 42364565 chr19:42364286-42364565 . RPS19
chr19 42373718 42373873 chr19:42373718-42373873 . RPS19

期望的输出

chr19 42363937 42364409 chr19:42363937-42364409 . RPS19
chr19 42364286 42364565 chr19:42364286-42364565 . RPS19

描述

line 1,2, and 5 match or fall into the range of `file1` and don't need to be printed.

为了获得所需的输出,我尝试了它并且执行时没有结果:

AWK

awk '
NR==FNR{for(i=$2;i<=$3;++i) d[$1,i] = $6; next}
!d[$1,$2]{print $0}' file2 file1

谢谢你:)。

1 个答案:

答案 0 :(得分:0)

while read; do
  grep -q "^$REPLY$" file1 || echo "$REPLY"
done< file2