0

这是文件的一小部分:

ATOM   1276 HB1  ALA    81       9.959   6.292   8.850
ATOM   1277 HB2  ALA    81       9.327   5.104  10.015
ATOM   1264 HG21 THR    80       7.466  11.485   7.678
ATOM   1265 HG22 THR    80       6.093  12.332   8.430
ATOM   1278 HB3  ALA    81       8.579   5.259   8.408
ATOM   1279 C    ALA    81       8.644   7.659  10.963
ATOM   1280 O    ALA    81       9.831   8.068  10.879
ATOM   1281 OXT  ALA    81       7.873   7.848  11.925
TER   
ATOM   1282 N    THR    82      25.394   2.987 -11.042
ATOM   1283 H1   THR    82      25.767   3.599 -10.330
ATOM   1284 H2   ALA    82      24.426   3.228 -11.202
ATOM   1285 H3   THR    82      26.042   2.957 -11.816
ATOM   1264 HG21 HIS    80       7.466  11.485   7.678
ATOM   1265 HG22 THR    80       6.093  12.332   8.430
ATOM   1286 CA   THR    82      25.370   1.609 -10.498
ATOM   1287 HA   THR    82      24.355   1.215 -10.451
TER

如果我将 ATOM 的“A”视为位置 1,我如何在第 4 列之后的一个空格(即第 21 位)添加“A”。这将持续到 TER,在 TER 之后它将添加“B”到同一位置。这种方式填充将如下所示:

ATOM   1276 HB1  ALA A   81       9.959   6.292   8.850
ATOM   1277 HB2  ALA A   81       9.327   5.104  10.015
ATOM   1264 HG21 THR A   80       7.466  11.485   7.678
ATOM   1265 HG22 THR A   80       6.093  12.332   8.430
ATOM   1278 HB3  ALA A   81       8.579   5.259   8.408
ATOM   1279 C    ALA A   81       8.644   7.659  10.963
ATOM   1280 O    ALA A   81       9.831   8.068  10.879
ATOM   1281 OXT  ALA A   81       7.873   7.848  11.925
TER   
ATOM   1282 N    THR B   82      25.394   2.987 -11.042
ATOM   1283 H1   THR B   82      25.767   3.599 -10.330
ATOM   1284 H2   ALA B   82      24.426   3.228 -11.202
ATOM   1285 H3   THR B   82      26.042   2.957 -11.816
ATOM   1264 HG21 HIS B   80       7.466  11.485   7.678
ATOM   1265 HG22 THR B   80       6.093  12.332   8.430
ATOM   1286 CA   THR B   82      25.370   1.609 -10.498
ATOM   1287 HA   THR B   82      24.355   1.215 -10.451
TER

如果在 linux 中可以做到这一点,Linux 命令将非常有帮助。如果这些更改发生在文件中并重写它会很好。任何帮助表示赞赏。谢谢你。

4

2 回答 2

1
awk '
    /^TER/ && x==0{
    x=1
}
NF>1{
    $4 = $4 " " (x ? "B" : "A")
}1' input.txt | column -t

ATOM  1276  HB1   ALA  A  81  9.959   6.292   8.850
ATOM  1277  HB2   ALA  A  81  9.327   5.104   10.015
ATOM  1264  HG21  THR  A  80  7.466   11.485  7.678
ATOM  1265  HG22  THR  A  80  6.093   12.332  8.430
ATOM  1278  HB3   ALA  A  81  8.579   5.259   8.408
ATOM  1279  C     ALA  A  81  8.644   7.659   10.963
ATOM  1280  O     ALA  A  81  9.831   8.068   10.879
ATOM  1281  OXT   ALA  A  81  7.873   7.848   11.925
TER
ATOM  1282  N     THR  B  82  25.394  2.987   -11.042
ATOM  1283  H1    THR  B  82  25.767  3.599   -10.330
ATOM  1284  H2    ALA  B  82  24.426  3.228   -11.202
ATOM  1285  H3    THR  B  82  26.042  2.957   -11.816
ATOM  1264  HG21  HIS  B  80  7.466   11.485  7.678
ATOM  1265  HG22  THR  B  80  6.093   12.332  8.430
ATOM  1286  CA    THR  B  82  25.370  1.609   -10.498
ATOM  1287  HA    THR  B  82  24.355  1.215   -10.451
TER
于 2012-04-26T13:06:15.057 回答
1

在特定偏移处插入字母的最简单方法(可能)是:

perl -i.bak -pwe 'substr( $_, 20, 0 ) = "A"' input-file

要处理您在 TER 之后更改替换的要求,您可以执行以下操作:

perl -i .bak -pwe 'if( m/^TER/ ) { $m = "B"; next }
    substr( $_, 20, 0 ) = $m || "A"' input-file
于 2012-04-26T13:05:44.687 回答