in reply to Re^2: awk 2 perl oneliner
in thread awk 2 perl oneliner
The only prob I have now is, when applied to my real data a ">" sign is missing at the beginning ... and one is too much at the end.
The reason for this is the way the records are being split. The first record (and only the first) will have a leading ">", and all records except for the last will have a trailing ">". Now, if you happen to not print out the first record (because it doesn't match) the initial ">" will be missing from the output file. Similarly, if you happen to not print the last record, there will be a stray ">" from the previous record.
The proper way to handle those corner cases would be to always remove any leading or trailing ">"s, and always add a new one for output:
... # scan second file while (<>) { s/^>//; # remove leading '>' s/>$//; # remove trailing '>' print ">$_" if /^([\w\d]+)/ && $names{$1}; # add ^ }
(This way, you also no longer need to allow a leading ">" in the regex (the >? part). )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: awk 2 perl oneliner
by space_agent (Acolyte) on Mar 07, 2010 at 12:57 UTC |