Reputation: 5
I am a beginner at Perl and have a section of data like the following:
ATOM 2067 N SER 7 316 -2.78500 -0.14800 -0.01300 N_R 3 0 -0.47000 0 0
ATOM 2068 HN SER 7 316 -2.51586 0.06218 0.89490 H___A 1 0 0.31000 0 0
ATOM 2069 CA SER 7 316 -3.57800 -1.36200 -0.28500 C_3 4 0 0.07000 0 0
I want to be able to print to another file lines of the data without H_ in each line. Could you help me identify the error in my regular expression.
while (<localBGF>)
{
$line = $_;
if ($line =~ /^ATOM\s+\d+\s+(\S+)\s+SER/)
{
if ($line !~ /^ATOM\s+\d+\s+(\S+)\s+SER\s+\d\s+\d\s+\d\s+\d\s+\d\s+H_/)
{
print BGF $line;
}
}
}
Upvotes: 0
Views: 100
Reputation: 802
Since you've already identified with the first regex that the line matches ^ATOM\s+\d+\s+(\S+)\s+SER
for the second you can just check that $line !~ /.*H_.*/
Upvotes: 1