#!/usr/bin/perl use strict; use warnings; use File::Find; use File::Slurp; my @dir = ( '/work' ); my $term = 'my term'; find( sub{ my @lines; -f and @lines = read_file( $File::Find::name ); # complete pathname to the file for my $line (@lines){ if ($line =~ /\A $term /x){ print $File::Find::dir # Directory name . q{/} . qq{[$_]} # file name . qq{ : $line}, "\n" # line matching the term + } } }, @dir );
Output: /work/subd0/subd1/[test_05022008.pl] : my_matching_line;
In reply to Re: RegEx to get file name from find results
by poolpi
in thread RegEx to get file name from find results
by vsailas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |