This is a test version of Biostars. For the public version, visit https://www.biostars.org.
replace first column based on third column in modeled PDB file

I've modeled a protein. Here I want to replace ATOM with HETATM when fourth column contains UNK. Here is a sample of pdb file.

ATOM   7525  HB2 PHE A 462      24.643 -50.200  29.725  1.00  0.00           H
ATOM   7526  HD1 PHE A 462      22.585 -51.535  30.162  1.00  0.00           H
ATOM   7527  HD2 PHE A 462      25.166 -52.418  26.825  1.00  0.00           H
ATOM   7528  HE1 PHE A 462      20.867 -53.074  29.206  1.00  0.00           H
ATOM   7529  HE2 PHE A 462      23.429 -53.905  25.870  1.00  0.00           H
ATOM   7530  HZ  PHE A 462      21.293 -54.268  27.091  1.00  0.00           H
TER    7531  HZ  PHE A 462
ATOM   7532  O1  UNK     1       8.575 -36.095  63.165  1.00  0.00           O
ATOM   7533  O2  UNK     1      10.566 -35.374  62.229  1.00  0.00           O
ATOM   7534  N3  UNK     1       6.742 -36.630  57.870  1.00  0.00           N
ATOM   7535  N4  UNK     1       9.871 -33.867  59.866  1.00  0.00           N
ATOM   7536  C5  UNK     1       8.179 -34.893  58.559  1.00  0.00           C
ATOM   7537  C6  UNK     1       6.720 -35.389  58.665  1.00  0.00           C

I've tried sed, but unable to give a condition on specific column and replace first column.

awk sed

1 answer

You can use awk for this:

awk '{if($4 == "UNK") $1 = "HETATM"; print}' file.pdb >mod_file.pdb

I thought it awk extracts the lines containing UNK. Thank you

You can move the comment to an answer :).

Log in to answer this question.