in reply to System Call for various serials in a for loop

Elbarto:

You ought to read the man page for grep. Not every problem is a perl problem:

grep -F -f serials.txt logs* >serials.log

if you want to use perl, then you don't really need grep, either:

# Code to load serial numbers into @serials goes here... while (<>) { for my $serial (@serials) { if (0 >= index($_, $serial) { print $_; next; } } }

...roboticus

Replies are listed 'Best First'.
Re^2: System Call for various serials in a for loop
by RMGir (Prior) on Jun 28, 2007 at 12:00 UTC
    If I could ++ 10 times that mention of grep -F -f..., I would.

    I didn't know about that grep option.

    For the perl approach, depending on the number of "serials", Regex::PreSuf might be able to turn @serials into one regex, which would likely be very ugly, but likely faster.

    However, it's likely to be impossible to beat doing the grep -F -f and then post-processing the results file to split into separate serial files - for example, if the serial column is easily found, the sort program could sort the result by serial #, making the split very simple.

    For bulk applications, /usr/bin/grep and /usr/bin/sort can sometimes beat perl's speed by large margins, so it's worth trying them.


    Mike