这是文件的一小部分:
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,如何在coloumn 4之后的一个空格中添加'A',即第21位。这将持续到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命令将非常有用。如果这些更改发生在文件中并重写它将会很好。任何帮助表示赞赏。
谢谢。
答案 0 :(得分: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
答案 1 :(得分: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