in reply to Re^2: usage of awk and grep together
in thread usage of awk and grep together

I would suggest playing with creating subs and passing them arguments if you haven't already. Like this example you can take code you already have and put them in a nice friendly named container. This is a fundamental skill that is very handy.

Call the sub with just the $fileid and $specificdata that you want given as arguments.

You retrieve the arguments very easily:

sub get_log_data { my ($fileid, $match) = @_; #...

Then just replace fileid with $fileid and specificdata with $match.

As you can see there are many other ways to do this. I provided the longest way I could think of because I hoped it would be easier to understand and learn from. Short one-liners generally have many subtle concepts that make them work. i.e. here is the sub using johngg's approach, one I would use for a quick n dirty script.

sub get_log_data { my ($fileid, $match) = @_; local @ARGV = 'logfile'; return join '', grep { (/$fileid/o .. /\A-{5}/) && /$match/o } <>; }

I'd suggest using a long, explicit, easy to debug, easy to understand version for a beginner; as a learning exercise.