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
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"
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |