如何在具有特定行数的特定列中用字母'H'替换字母'L'?

时间:2014-06-24 10:33:03

标签: shell awk sed

我想替换字母" L"字母" H"在库尔特5和从2334到2343的起始行。我怎么能这样做

ATOM   2328  C   PRO H 216       2.775  27.948  31.304  1.00 54.68           C  
ANISOU 2328  C   PRO H 216     6662   6876   7238    231   -273   -901       C  
ATOM   2329  O   PRO H 216       3.081  27.188  32.221  1.00 33.86           O  
ANISOU 2329  O   PRO H 216     4076   4302   4486    297   -305   -920       O  
ATOM   2330  CB  PRO H 216       0.348  28.666  31.322  1.00 32.21           C  
ANISOU 2330  CB  PRO H 216     3856   4070   4311    245   -165   -866       C  
ATOM   2331  CG  PRO H 216      -0.233  27.810  32.376  1.00 35.76           C  
ANISOU 2331  CG  PRO H 216     4380   4616   4590    319   -134   -850       C  
ATOM   2332  CD  PRO H 216      -0.205  26.395  31.831  1.00 29.01           C  
ANISOU 2332  CD  PRO H 216     3545   3784   3691    274    -64   -735       C  
TER    2333      PRO H 216                                                      
ATOM   2334  N   ASP L   1      12.679   9.090 -25.911  1.00 24.97           N  
ANISOU 2334  N   ASP L   1     3340   2560   3588     66     89   -196       N  
ATOM   2335  CA  ASP L   1      11.386   9.008 -25.214  1.00 22.13           C  
ANISOU 2335  CA  ASP L   1     3001   2290   3117     87     13   -178       C  
ATOM   2336  C   ASP L   1      10.586  10.270 -25.405  1.00 24.75           C  
ANISOU 2336  C   ASP L   1     3332   2595   3476    107     45   -149       C  
ATOM   2337  O   ASP L   1      11.150  11.366 -25.533  1.00 25.78           O  
ANISOU 2337  O   ASP L   1     3423   2631   3741    109    104   -176       O  
ATOM   2338  CB  ASP L   1      11.594   8.775 -23.699  1.00 23.18           C  
ANISOU 2338  CB  ASP L   1     3081   2475   3250    109    -77   -274       C  
ATOM   2339  CG  ASP L   1      12.293   7.471 -23.340  1.00 26.65           C  
ANISOU 2339  CG  ASP L   1     3535   2947   3645    108   -126   -303       C  
ATOM   2340  OD1 ASP L   1      12.541   6.650 -24.258  1.00 24.18           O  
ANISOU 2340  OD1 ASP L   1     3268   2622   3300     81    -97   -250       O  
ATOM   2341  OD2 ASP L   1      12.537   7.243 -22.126  1.00 26.04           O  
ANISOU 2341  OD2 ASP L   1     3432   2911   3553    145   -200   -379       O  
ATOM   2342  N   ILE L   2       9.260  10.129 -25.359  1.00 19.52           N  
ANISOU 2342  N   ILE L   2     2706   2012   2698    123      3   -103       N  
ATOM   2343  CA  ILE L   2       8.371  11.280 -25.505  1.00 19.22           C  
ANISOU 2343  CA  ILE L   2     2671   1960   2672    154     16    -82       C  
.
.
.
.
HETATM 4661  O   HOH L2236       8.200  18.486   2.750  1.00 58.70           O  
HETATM 4662  O   HOH L2237       2.087  16.407   1.748  1.00 45.02           O  
HETATM 4663  O   HOH L2238       1.933  41.087   7.631  1.00 31.01           O  
HETATM 4664  O   HOH L2239       4.744  42.515  11.051  1.00 60.18           O  
HETATM 4665  O   HOH L2240       2.258  41.306  12.333  1.00 45.78           0

预期结果

ATOM   2328  C   PRO H 216       2.775  27.948  31.304  1.00 54.68           C  
ANISOU 2328  C   PRO H 216     6662   6876   7238    231   -273   -901       C  
ATOM   2329  O   PRO H 216       3.081  27.188  32.221  1.00 33.86           O  
ANISOU 2329  O   PRO H 216     4076   4302   4486    297   -305   -920       O  
ATOM   2330  CB  PRO H 216       0.348  28.666  31.322  1.00 32.21           C  
ANISOU 2330  CB  PRO H 216     3856   4070   4311    245   -165   -866       C  
ATOM   2331  CG  PRO H 216      -0.233  27.810  32.376  1.00 35.76           C  
ANISOU 2331  CG  PRO H 216     4380   4616   4590    319   -134   -850       C  
ATOM   2332  CD  PRO H 216      -0.205  26.395  31.831  1.00 29.01           C  
ANISOU 2332  CD  PRO H 216     3545   3784   3691    274    -64   -735       C  
TER    2333      PRO H 216                                                      
ATOM   2334  N   ASP H   1      12.679   9.090 -25.911  1.00 24.97           N  
ANISOU 2334  N   ASP H   1     3340   2560   3588     66     89   -196       N  
ATOM   2335  CA  ASP H   1      11.386   9.008 -25.214  1.00 22.13           C  
ANISOU 2335  CA  ASP H   1     3001   2290   3117     87     13   -178       C  
ATOM   2336  C   ASP H   1      10.586  10.270 -25.405  1.00 24.75           C  
ANISOU 2336  C   ASP H   1     3332   2595   3476    107     45   -149       C  
ATOM   2337  O   ASP H   1      11.150  11.366 -25.533  1.00 25.78           O  
ANISOU 2337  O   ASP H   1     3423   2631   3741    109    104   -176       O  
ATOM   2338  CB  ASP H   1      11.594   8.775 -23.699  1.00 23.18           C  
ANISOU 2338  CB  ASP H   1     3081   2475   3250    109    -77   -274       C  
ATOM   2339  CG  ASP H   1      12.293   7.471 -23.340  1.00 26.65           C  
ANISOU 2339  CG  ASP H   1     3535   2947   3645    108   -126   -303       C  
ATOM   2340  OD1 ASP H   1      12.541   6.650 -24.258  1.00 24.18           O  
ANISOU 2340  OD1 ASP H   1     3268   2622   3300     81    -97   -250       O  
ATOM   2341  OD2 ASP H   1      12.537   7.243 -22.126  1.00 26.04           O  
ANISOU 2341  OD2 ASP H   1     3432   2911   3553    145   -200   -379       O  
ATOM   2342  N   ILE H   2       9.260  10.129 -25.359  1.00 19.52           N  
ANISOU 2342  N   ILE H   2     2706   2012   2698    123      3   -103       N  
ATOM   2343  CA  ILE H   2       8.371  11.280 -25.505  1.00 19.22           C  
ANISOU 2343  CA  ILE H   2     2671   1960   2672    154     16    -82       C  
.
.
.
.
HETATM 4661  O   HOH L2236       8.200  18.486   2.750  1.00 58.70           O  
HETATM 4662  O   HOH L2237       2.087  16.407   1.748  1.00 45.02           O  
HETATM 4663  O   HOH L2238       1.933  41.087   7.631  1.00 31.01           O  
HETATM 4664  O   HOH L2239       4.744  42.515  11.051  1.00 60.18           O  
HETATM 4665  O   HOH L2240       2.258  41.306  12.333  1.00 45.78           0

5 个答案:

答案 0 :(得分:3)

这适用于您的输入样本:

sed '/2334/,/ANISOU 2343/s/ L / H /'

请注意,它不会检查列号,您可能需要调整表达式来执行此操作。

答案 1 :(得分:2)

您可以使用sed

sed '2334,2343s/\([^ ]* \+\)L/\1H/' input.txt

答案 2 :(得分:2)

使用sed

sed '2334,2343s/\(\([^ ]* \)\{4\}\)L/\1 H/' input

答案 3 :(得分:0)

您可以使用awk:

awk 'NR>=2334 && NR<=2343 {gsub(/L/, "H", $5)} 1' file

答案 4 :(得分:0)

试试这个awk命令,

awk '$2>=2334 && $2<=2343 {gsub(/L/,"H",$5)}1' file