0

我有一个像这样的文件

TER 
ATOM  18351  C12 PA      1      22.484  26.043  12.870  1.00  0.00      MEMB
ATOM  18352  H2R PA      1      21.907  26.993  12.853  1.00  0.00      MEMB
ATOM  18353  H2S PA      1      22.369  25.522  11.895  1.00  0.00      MEMB
ATOM  18401  C13 PA      1      23.999  26.415  12.988  1.00  0.00      MEMB
ATOM  18402  H3R PA      1      24.586  25.473  12.934  1.00  0.00      MEMB
ATOM  18403  H3S PA      1      24.188  26.890  13.975  1.00  0.00      MEMB
ATOM  18404  C14 PA      1      24.389  27.402  11.877  1.00  0.00      MEMB
ATOM  18405  H4R PA      1      25.379  27.803  12.184  1.00  0.00      MEMB
ATOM  18406  H4S PA      1      23.777  28.329  11.879  1.00  0.00      MEMB
ATOM  18407  C15 PA      1      24.484  26.765  10.484  1.00  0.00      MEMB
TER
ATOM  18408  H5R PA      1      23.540  26.275  10.164  1.00  0.00      MEMB
ATOM  18409  H5S PA      1      25.223  25.936  10.474  1.00  0.00      MEMB
ATOM  18410  C16 PA      1      24.922  27.998   9.564  1.00  0.00      MEMB
ATOM  18411  H6R PA      1      25.694  28.592  10.099  1.00  0.00      MEMB
ATOM  18412  H6S PA      1      24.035  28.658   9.457  1.00  0.00      MEMB
ATOM  18413  C17 PA      1      25.447  27.503   8.237  1.00  0.00      MEMB
ATOM  18414  H7R PA      1      25.871  26.479   8.305  1.00  0.00      MEMB
ATOM  18415  H7S PA      1      26.266  28.169   7.891  1.00  0.00      MEMB

我希望在第 5 列中的每个 TER 之后增加 1,以便输出文件看起来像:

TER 
ATOM  18351  C12 PA      1      22.484  26.043  12.870  1.00  0.00      MEMB
ATOM  18352  H2R PA      1      21.907  26.993  12.853  1.00  0.00      MEMB
ATOM  18353  H2S PA      1      22.369  25.522  11.895  1.00  0.00      MEMB
ATOM  18401  C13 PA      1      23.999  26.415  12.988  1.00  0.00      MEMB
ATOM  18402  H3R PA      1      24.586  25.473  12.934  1.00  0.00      MEMB
ATOM  18403  H3S PA      1      24.188  26.890  13.975  1.00  0.00      MEMB
ATOM  18404  C14 PA      1      24.389  27.402  11.877  1.00  0.00      MEMB
ATOM  18405  H4R PA      1      25.379  27.803  12.184  1.00  0.00      MEMB
ATOM  18406  H4S PA      1      23.777  28.329  11.879  1.00  0.00      MEMB
ATOM  18407  C15 PA      1      24.484  26.765  10.484  1.00  0.00      MEMB
TER
ATOM  18408  H5R PA      2      23.540  26.275  10.164  1.00  0.00      MEMB
ATOM  18409  H5S PA      2      25.223  25.936  10.474  1.00  0.00      MEMB
ATOM  18410  C16 PA      2      24.922  27.998   9.564  1.00  0.00      MEMB
ATOM  18411  H6R PA      2      25.694  28.592  10.099  1.00  0.00      MEMB
ATOM  18412  H6S PA      2      24.035  28.658   9.457  1.00  0.00      MEMB

文件的格式也不应该改变。

4

2 回答 2

0

perl:

perl -lane 'if(/TER/){$count++}unless(/TER/){$F[4]=$count;}print "@F"' your_file

awk:

awk '/TER/{count++}{$5=count}1' your_file
于 2013-03-11T09:53:05.323 回答
0

1如果第五列是唯一在您的数据中有一个整数的列,那么在不更改格式的情况下这样做是一种肮脏的方法:

perl -pe '$c++if/TER/;s/\b1\b/$c/' input_file
于 2013-03-11T13:10:54.453 回答