Recursive Search and Grep Utility Written by sierrathedog04, sierrathedog04@hotmail.com, 6/01
- The first parameter is a regular expression which matches the filenames that you wish to search for. It defaults to '.*'
- The second parameter is a regular expression for which you wish to grep your found files. It defaults to '.*'
- The third parameter is the directory from which you will start your recursive search. It defaults to '.'
Tested on Perl 5.005_02 in a MP-RAS Unix environment.
Updated 6/19 to add line inadvertently left off original posting.
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 |
Back to
Cool Uses for Perl