|
|
| Perl Monk, Perl Meditation | |
| PerlMonks |
Re: extracting words with certain charactersby space_monk (Chaplain) |
| on Dec 04, 2012 at 10:44 UTC ( #1007056=note: print w/ replies, xml ) | Need Help?? |
|
Update: Just had to make a correction for multiple matches on one line... perl -ne 'while (/(\w*_\w*)/g) { print "$1\n";}' code_file(s)You may want to change the regex to accept only names with a leading alpha character, or so it must contain at least one alpha character, or save the names into a hash to remove duplicates, so YMMV from what I've produced here... Mapping into a hash using: perl -ne 'BEGIN { my %hash; }; END { print map { "$_\n"} keys %hash} while (/(\w*_\w*)/g) { $hash{$1}=1};' code_file(s)Gives all the unique names, e.g.
A Monk aims to give answers to those who have none, and to learn from those who know more.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||