1

I have file with lines that start with two possible keywords, ATOM and HETATM. In some of those lines, there is a second keyword HOH, appearing after some other characters. In other lines, there are other 3-character keywords XXX like SOL instead of HOH:

ATOM 1231 O XXX ... HETATM1232 O SOL ... HETATM1233 O HOH ... 

What I want to do is to change HETATMs to ATOM only if HOH also appears on the line.

I tried the following:

sed -E '/\(HETATM\)\(.*HOH\)/s//\1ATOM/' file 

which gives the illegal byte sequence error. What am I doing wrong?

1 Answer 1

2

Try this:

sed '/HOH/s/HETATM/ATOM/' file 

Output:

 ATOM 1231 O XXX ... HETATM1232 O SOL ... ATOM1233 O HOH ... 

Only in lines which contain HOH search HETATM and replace by ATOM.

Sign up to request clarification or add additional context in comments.

3 Comments

It does give the desired output, but also gives the same error at the end.
Actually, it doesn't print all the file. It stops at line 14095.
Ok, I think it was because I have a weird character at that line. When I do head -n10000 file | sed '/HOH/s/HETATM/ATOM/' it works fine. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.