use strict; use File::Find; my $glob = shift || '.*'; my $grepTerm = shift || '.*'; my $dir = shift || "."; #following line added 6/19. (Inadvertently left off original posting:) find (\&Wanted, $dir); sub Wanted { return unless /$glob/; open (CURRENT_FILE, $_); my @currentFile = <CURRENT_FILE>; my @foundLines = grep /$grepTerm/, @currentFile; print "In $File::Find::dir/$_:\n" if @foundLines; foreach (@foundLines) { print " $_\n"; } } print "Completed recursive search for files named $glob containing ter +m $grepTerm in directory $dir";
|
---|
Replies are listed 'Best First'. | |
---|---|
Knob Re: Recursive Grep
by knobunc (Pilgrim) on Jun 19, 2001 at 16:14 UTC | |
by John M. Dlugosz (Monsignor) on Jun 19, 2001 at 19:37 UTC | |
Re: Recursive Grep
by John M. Dlugosz (Monsignor) on Jun 19, 2001 at 19:42 UTC | |
by sierrathedog04 (Hermit) on Jun 19, 2001 at 20:03 UTC | |
Re: Recursive Grep
by Anonymous Monk on Jul 01, 2010 at 19:52 UTC |