Most of the solutions above are fine -- especially hardburn's one-liner (that one got my ++!) -- but folks who know about unix command-line tools know that this is usually just a job for the "grep" command:
grep 'pattern to be kept' old.file > new.file
Of course, perl offers so much that "grep" can't do: more powerful regexes, support for multiple character encodings, and liberation from the old "every record must be just one line of text" mind-set. How about a Perl version of grep?
Well, I'm sure I'm not the only who has done this -- I just couldn't stop myself... Here it is: grepp -- Perl version of grep (I wrote it a year or so ago, have been using it regularly on solaris, linux and macosx -- should work fine on ms-windows -- and finally got around to posting it here).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||