打印文件中与另一个文件中的字符匹配的行

打印文件中与另一个文件中的字符匹配的行

我感兴趣的是如何执行一项任务:

我有文件1:

TRP   141
HIS   172
ALA   173

和我的文件2:

ATOM    295  CB  GLN   139      10.898   0.612  22.999
ATOM    296  CG  GLN   139      10.170   1.178  24.218
ATOM    297  CD  GLN   139      10.037   0.191  25.374
ATOM    298  OE1 GLN   139      10.426  -0.961  25.269
ATOM    299  NE2 GLN   139       9.481   0.655  26.482
ATOM    300  N   VAL   140      11.526   0.196  19.833
ATOM    301  CA  VAL   140      12.435  -0.188  18.760
ATOM    302  C   VAL   140      12.949   1.048  18.004
ATOM    303  O   VAL   140      14.135   1.143  17.669
ATOM    304  CB  VAL   140      11.753  -1.176  17.782
ATOM    305  CG1 VAL   140      12.534  -1.292  16.480
ATOM    306  CG2 VAL   140      11.596  -2.541  18.426
ATOM    307  N   TRP   141      12.057   1.998  17.748
ATOM    308  CA  TRP   141      12.410   3.177  16.968
ATOM    309  C   TRP   141      13.005   4.292  17.817
ATOM    310  O   TRP   141      13.888   5.006  17.356
ATOM    311  CB  TRP   141      11.208   3.678  16.176
ATOM    312  CG  TRP   141      10.729   2.678  15.166
ATOM    313  CD1 TRP   141       9.562   1.982  15.208
ATOM    314  CD2 TRP   141      11.412   2.252  13.976
ATOM    315  NE1 TRP   141       9.454   1.169  14.110
ATOM    316  CE2 TRP   141      10.579   1.308  13.340
ATOM    317  CE3 TRP   141      12.639   2.582  13.381
ATOM    318  CZ2 TRP   141      10.926   0.693  12.137
ATOM    319  CZ3 TRP   141      12.988   1.962  12.189
ATOM    320  CH2 TRP   141      12.133   1.032  11.580
ATOM    321  N   SER   142      12.544   4.454  19.048
ATOM    322  CA  SER   142      13.179   5.445  19.912
ATOM    323  C   SER   142      14.602   5.035  20.296
ATOM    324  O   SER   142      15.414   5.894  20.644
ATOM    325  CB  SER   142      12.355   5.730  21.157
ATOM    326  OG  SER   142      12.122   4.565  21.903
ATOM    327  N   ASN   143      14.911   3.737  20.204
ATOM    328  CA  ASN   143      16.273   3.231  20.454
ATOM    329  C   ASN   143      17.320   3.814  19.517
ATOM    330  O   ASN   143      18.499   3.879  19.869
ATOM    331  CB  ASN   143      16.355   1.704  20.268
ATOM    332  CG  ASN   143      15.766   0.913  21.419
ATOM    333  OD1 ASN   143      15.510   1.439  22.497
ATOM    334  ND2 ASN   143      15.558  -0.380  21.185
ATOM    335  N   VAL   144      16.894   4.189  18.313
ATOM    543  N   HIS   172      -8.982   3.379   2.407
ATOM    544  CA  HIS   172      -8.156   2.181   2.287
ATOM    545  C   HIS   172      -8.737   0.986   3.063
ATOM    546  O   HIS   172      -8.438   0.793   4.231
ATOM    547  CB  HIS   172      -6.734   2.506   2.757
ATOM    548  CG  HIS   172      -6.139   3.708   2.084
ATOM    549  ND1 HIS   172      -6.132   4.960   2.661
ATOM    550  CD2 HIS   172      -5.544   3.851   0.875
ATOM    551  CE1 HIS   172      -5.552   5.819   1.841
ATOM    552  NE2 HIS   172      -5.186   5.171   0.750
ATOM    553  N   ALA   173      -9.550   0.170   2.395
ATOM    554  CA  ALA   173     -10.284  -0.922   3.052
ATOM    555  C   ALA   173      -9.432  -2.158   3.323
ATOM    556  O   ALA   173      -8.509  -2.466   2.570
ATOM    557  CB  ALA   173     -11.485  -1.309   2.200
ATOM    558  N   PHE   174      -9.773  -2.875   4.397
ATOM    559  CA  PHE   174      -9.194  -4.180   4.677
ATOM    560  C   PHE   174      -9.983  -5.307   3.968
ATOM    561  O   PHE   174     -11.075  -5.081   3.423
ATOM    562  CB  PHE   174      -9.124  -4.414   6.189
ATOM    563  CG  PHE   174      -8.071  -3.581   6.908

输出:

ATOM    307  N   TRP   141      12.057   1.998  17.748
ATOM    308  CA  TRP   141      12.410   3.177  16.968
ATOM    309  C   TRP   141      13.005   4.292  17.817
ATOM    310  O   TRP   141      13.888   5.006  17.356
ATOM    311  CB  TRP   141      11.208   3.678  16.176
ATOM    312  CG  TRP   141      10.729   2.678  15.166
ATOM    313  CD1 TRP   141       9.562   1.982  15.208
ATOM    314  CD2 TRP   141      11.412   2.252  13.976
ATOM    315  NE1 TRP   141       9.454   1.169  14.110
ATOM    316  CE2 TRP   141      10.579   1.308  13.340
ATOM    317  CE3 TRP   141      12.639   2.582  13.381
ATOM    318  CZ2 TRP   141      10.926   0.693  12.137
ATOM    319  CZ3 TRP   141      12.988   1.962  12.189
ATOM    320  CH2 TRP   141      12.133   1.032  11.580
ATOM    543  N   HIS   172      -8.982   3.379   2.407
ATOM    544  CA  HIS   172      -8.156   2.181   2.287
ATOM    545  C   HIS   172      -8.737   0.986   3.063
ATOM    546  O   HIS   172      -8.438   0.793   4.231
ATOM    547  CB  HIS   172      -6.734   2.506   2.757
ATOM    548  CG  HIS   172      -6.139   3.708   2.084
ATOM    549  ND1 HIS   172      -6.132   4.960   2.661
ATOM    550  CD2 HIS   172      -5.544   3.851   0.875
ATOM    551  CE1 HIS   172      -5.552   5.819   1.841
ATOM    552  NE2 HIS   172      -5.186   5.171   0.750
ATOM    553  N   ALA   173      -9.550   0.170   2.395
ATOM    554  CA  ALA   173     -10.284  -0.922   3.052
ATOM    555  C   ALA   173      -9.432  -2.158   3.323
ATOM    556  O   ALA   173      -8.509  -2.466   2.570
ATOM    557  CB  ALA   173     -11.485  -1.309   2.200

基本上,只要在文件 2 的行中找到文件 1 中的字符;在输出中打印所有这些行。

有人能帮我解决这个问题吗?

答案1

grep可以匹配文件中的字符串:

grep -F -f file1 file2

相关内容