[英]Merging two txt files using bash
I have: pull of txt files consisted of many strings and one reference.txt (short) file my bash script doing the following things: 1) while looping of pull of txt files it performs something with each of the files (not changing it composition) after which it 2) should merge composition of each files with the composition of reference.txt in specified position 我有:由很多字符串和一个reference.txt(短)文件组成的txt文件提取,我的bash脚本执行以下操作:1)在循环txt文件的提取循环时,它对每个文件执行某些操作(不更改其组成) )之后2)应该将每个文件的组成与reference.txt的组成在指定位置合并
eg the ending of each of workfiles looks like 例如,每个工作文件的结尾看起来像
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
here I should to substitute th last string "END" on the full text taken from reference.pdb 在这里,我应该用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
obtaining eventually for each of the lopped file smth like: 最终获得每个类似文件的文件:
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
With sed, to insert the content of reference.pdb before END
string : 使用sed,可将reference.pdb的内容插入END
字符串之前:
sed '
/END/ {
r reference.pdb
a END
d
}
' workfile
Edit : 编辑:
If the filename is stored in a variable, the sed command must be surrounded with double quotes : 如果文件名存储在变量中,则sed命令必须用双引号引起来:
ref=reference.pdb
sed "
/END/ {
r $ref
a END
d
}
" workfile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.