使用bash合并两个txt文件

时间:2016-06-30 13:25:38

标签: bash

我有: txt文件的拉动由许多字符串组成 和一个reference.txt(短)文件 我的bash脚本执行以下操作: 1)在循环拉出txt文件的同时,它会对每个文件执行一些操作(不改变它的组成) 2)应将每个文件的组成与reference.txt的组合合并到指定位置

例如,每个工作文件的结尾看起来像

ATOM  13703  HA  GLN   100      83.311  32.648  23.654  0.1232 1.3870
ATOM  13704  HG2 GLN   100      82.879  33.518  22.168  0.0203 1.4870
ATOM  13705  HB2 GLN   100      84.606  31.260  21.824  0.0452 1.4870
ATOM  13706 HE22 GLN   100      84.225  34.975  20.004  0.4304 0.6000
ATOM  13707  OE1 GLN   100      82.389  32.538  19.564 -0.6098 1.6612
ATOM  13708  NE2 GLN   100      83.817  34.212  19.506 -0.9574 1.8240
ATOM  13709 HE21 GLN   100      83.663  34.375  18.529  0.4304 0.6000
TER
END

这里我应该替换从reference.pdb

获取的全文中的最后一个字符串“END”
HETATM 5420 CU    CU A 559      54.926  67.840  66.647  1.00 47.11          CU  
HETATM 5421 MG    MG A 560      58.119  65.472  53.773  1.00 12.89          MG  
HETATM 5422 CA    CA A 561      78.459  57.926  52.401  1.00 22.70          CA 
HETATM 7924 CU    CU B 270      62.144  60.705  47.277  1.00 40.39          CU  
HETATM 7925 CU    CU B 271      60.809  60.526  45.118  1.00 44.84          CU

最终获得每个lopped文件smth,如:

ATOM  13695  O   GLN   100      82.103  30.697  24.719 -0.8042 1.6612
ATOM  13696  CB  GLN   100      83.798  31.641  22.204 -0.0664 1.9080
ATOM  13697  CG  GLN   100      83.606  33.044  21.616 -0.0210 1.9080
ATOM  13698  CD  GLN   100      83.251  33.196  20.146  0.7093 1.9080
ATOM  13699  H   GLN   100      85.355  33.328  24.357  0.2681 0.6000
ATOM  13700  OXT GLN   100      83.889  29.761  24.981 -0.8042 1.6612
ATOM  13701  HG3 GLN   100      84.467  33.577  21.792  0.0203 1.4870
ATOM  13702  HB3 GLN   100      82.992  31.127  22.034  0.0452 1.4870
ATOM  13703  HA  GLN   100      83.311  32.648  23.654  0.1232 1.3870
ATOM  13704  HG2 GLN   100      82.879  33.518  22.168  0.0203 1.4870
ATOM  13705  HB2 GLN   100      84.606  31.260  21.824  0.0452 1.4870
ATOM  13706 HE22 GLN   100      84.225  34.975  20.004  0.4304 0.6000
ATOM  13707  OE1 GLN   100      82.389  32.538  19.564 -0.6098 1.6612
ATOM  13708  NE2 GLN   100      83.817  34.212  19.506 -0.9574 1.8240
ATOM  13709 HE21 GLN   100      83.663  34.375  18.529  0.4304 0.6000
TER
HETATM 5420 CU    CU A 559      54.926  67.840  66.647  1.00 47.11          CU  
HETATM 5421 MG    MG A 560      58.119  65.472  53.773  1.00 12.89          MG  
HETATM 5422 CA    CA A 561      78.459  57.926  52.401  1.00 22.70          CA 
HETATM 7924 CU    CU B 270      62.144  60.705  47.277  1.00 40.39          CU  
HETATM 7925 CU    CU B 271      60.809  60.526  45.118  1.00 44.84          CU
END

1 个答案:

答案 0 :(得分:4)

使用sed,在require 'aws/decider' require 'aws-sdk' class U_Act extend AWS::Flow::Activities activity :b_u do { version: "1.0" } end def b_u(c_id) lambda=Aws::Lambda::Client.new( access_key_id: “XxXXXXXXXXX”, secret_access_key: “XXXXXXXXXX” ) resp = lambda.invoke( function_name: “s_u_1” # required ) print "#{resp}" end 字符串之前插入reference.pdb的内容:

END

修改:

如果文件名存储在变量中,则sed命令必须用双引号括起来:

sed '
/END/ {
r reference.pdb
a END
d
}
' workfile