princepawn has asked for the wisdom of the Perl Monks concerning the following question:
I have a series of tab-separated files which look like this:
Because the second field represents a zip code, I want to kill any lines in a file which do not conform to zip code requirements. However, my perl one-liner attempts are failing. How can I get this one-liner to change the file so that only lines which match my filter stay? Here is my attempt:
1 7083 1 7530 1 ---------- 1 -7840 3 0 20 00000 4 00001 1 00007 3 00010 1 00011 1 00023 2 00044 3 00100 1 00101 1 00112 1 00120 1 00121 1 00149 1 00186 1 00193 1 00200 2 00202 4 00683 3 00725 3 00727 1 00731 1 00735 1 00738 1 00745 1 00749 1 00761 1 00777 2 00778 1 00784 3 00801 12 00802 3 00803 1 00820 4 00823
Because the second field represents a zip code, I want to kill any lines in a file which do not conform to zip code requirements. However, my perl one-liner attempts are failing. How can I get this one-liner to change the file so that only lines which match my filter stay? Here is my attempt:
[tbone@MDB zip-grok]$ perl -pi.bak -e '($count, $zip) = split /\t/; ch +omp $zip; warn "*$zip*"; next unless ( ($zip =~ /\d{5}/) and ($zip > +713) and ($zip < 99930) )' *.dat
Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality
edited by ybiC: balanced <readmore> tags
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: In-place file filtering
by Paladin (Vicar) on Jul 24, 2003 at 19:30 UTC | |
Re: In-place file filtering
by RMGir (Prior) on Jul 24, 2003 at 19:56 UTC | |
Re: In-place file filtering
by skyknight (Hermit) on Jul 24, 2003 at 19:33 UTC | |
Re: In-place file filtering
by dragonchild (Archbishop) on Jul 24, 2003 at 19:35 UTC | |
Re: In-place file filtering
by adrianh (Chancellor) on Jul 24, 2003 at 21:10 UTC | |
by princepawn (Parson) on Jul 24, 2003 at 22:11 UTC | |
by adrianh (Chancellor) on Jul 24, 2003 at 22:17 UTC | |
by princepawn (Parson) on Jul 24, 2003 at 23:36 UTC | |
by adrianh (Chancellor) on Jul 25, 2003 at 01:10 UTC | |
by Anonymous Monk on Jul 25, 2003 at 21:19 UTC | |
Re: In-place file filtering
by flounder99 (Friar) on Jul 24, 2003 at 20:28 UTC | |
by dragonchild (Archbishop) on Jul 24, 2003 at 20:40 UTC |
Back to
Seekers of Perl Wisdom