Sorry it's been so long getting back... Rough week!

Wow... Love the responces! Pleasant! Informative! Educational! The way it should be. Thank you!

Got it ... Understood it and I Thank you! Thank you! Thank you!

Just to make it clear... PORNUM = Part Number = materialSIZExSIZE@PoreSize = Filtration materials!

Long post ... Sorry! The important part is said!

I was close, My regex is where _ I _ was broke ... My last attempt was "m/^PORNUM: .*/xsm", however I was all over the place.

bart's regex did not allow spaces in the key Value. So the final regex is a slightly modified version of spazm's.

Following are two methods of my end results for the next in need! The better one is ... ???

Method 1, based on my original code.

#!/bin/sh perl -i~ -e ' # -i~ for in-place editing with tilde backup use strict; use warnings; my @a; my %excludehash; my $file = shift; open(excludelist, "< $file") or die; chomp( @a=<excludelist> ); close(excludelist); @excludehash{@a}=@a; { local($/) = ""; while (<>) { m/YOURKEY:\s+(.*)$/m; print unless exists $excludehash{ $1 } } }' "excludefile" "datafile"

Method 2, Based on spazm's example.

#!/bin/sh perl -i~ -e ' # -i~ for in-place editing with tilde backup use strict; use warnings; my %excludehash; my $file = shift; open(my $excludelist, "<", $file) or die; while(<$excludelist>) { chomp; next if /^$/; $excludehash{ $_ }=1; } close($excludelist); { local($/) = ""; while (<>) { next if ( m/^YOURKEY:\s+(.*)$/m && $excludehash{ $1 } ); print } }' "excludefile" "datafile"

Example excludefile & datafile

Example excludefile
1@1 Last, First

Example datafile

random lines of data YOURKEY: 1@1 random lines of data random lines of data random lines of data YOURKEY: 2/ random lines of data YOURKEY: Last, First random lines of data random lines of data random lines of data YOURKEY: Apple's

And my newly aquired understanding of hash'es allowed me to do the following. This was run on a data file of ~26M with 80,743 records and took less than 15 seconds to weed out 20,271 obsolete records leaving 60,472 ... !!! Sorry for the spill, I just think that is incredible speed! Especially on a FBSD7.1R PIII-866!

It took over 3 hours to print it out of the existing system! A newer system running M$lop Explode! (think it's a Pentium dual core)

YES ... I was impressed! And for that I thank you all again and again!

My purge tool!

#!/bin/sh perl -i~ -e ' use strict; use warnings; my %excludehash; { local($/) = ""; { while(<>) { while (m/^OBSPOR: (.*)$/mg) { $excludehash{ $1 } = $1 } last if (eof) } } seek(ARGV, 0, 0); { while (<>) { m/^PORNUM:\s+(.*)$/m; print unless exists $excludehash{ $1 } } } }' "datafile"

Thanks!

In reply to Re^2: Deleting paragraphs based on match in a hash by Anonymous Monk
in thread Deleting paragraphs based on match in a hash by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.