in reply to Extract the matching strings
But basically look for the keywords and if found, use split to extract either the 2nd thing on the line or the last thing on the line. All sorts of complex things are possible, but if you don't need them, then don't do it!
#!/usr/bin/perl -w use strict; my $protname; my $rna; while (<DATA>) #while (<PROTEIN>) in your case { if (/^VERSION/) { $protname = (split)[1]; } elsif (/^DBSOURCE/) { $rna = (split)[-1]; } } print "protname = $protname\n"; print "rna = $rna\n"; __END__ PRINTS: protname = YP_001648463.1 rna = NC_010202.1 __DATA__ LOCUS YP_001648463 258 aa linear INV 17 +-JUN-2009 DEFINITION cytochrome c oxidase subunit II [Ephydatia muelleri]. ACCESSION YP_001648463 VERSION YP_001648463.1 GI:164420795 DBLINK Project: 28177 DBSOURCE REFSEQ: accession NC_010202.1 KEYWORDS . ....
|
|---|