From comp.lang.perl.misc Thu Mar 13 19:30:10 1997 Path: news.panix.com!panix!news.mathworks.com!news.maxwell.syr.edu!news-feed.inet.tele.dk!mr.net!news-out.communique.net!news.ultranet.com!not-for-mail From: Dan Schmidt Newsgroups: comp.lang.perl.misc Subject: Re: Regex searches in all files (or selected files) in a directory Date: 13 Mar 1997 11:16:15 -0500 Organization: UltraNet Communications, Inc. Lines: 132 Message-ID: References: <33217DAE.3D66@indiana.edu> NNTP-Posting-Host: 146.115.90.78 X-Newsreader: Gnus v5.4.19/Emacs 19.34 jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey) writes: | David Parkhurst wrote: | |> I'd like to use regex to search all *.txt files (say) in a particular | |> directory that match some pattern. I'm working in Windows95, and I'm a | | You might find my 'search' program useful. | It's at | http://enterprise.ic.gc.ca/~jfriedl/perl search.pl is indeed amazingly useful. I had to make some changes to make it work under Windows 95; here's the patch (Jeffrey has noted it but hasn't had time to approve it, so it might be slightly (or completely) different in the next real release). Put the line "option: -win" in your .search file so it knows to do the special Win95 stuff. Note also that you MUST have the environment variable HOME set, as that's where it looks for the .search configuration file. Dan ----- patch follows ----- *** c:/src/old/search.pl Tue Feb 11 20:33:10 1997 --- c:/src/search.pl Wed Feb 12 11:49:02 1997 *************** *** 123,128 **** --- 123,131 ---- $retval=1; ## will set to 0 if we find anything. $DESCEND_SUBDIRECTORIES=1;## set to false by -depth=0 + $WINDOWS=0; ## under windows? + $USE_INODES=1; ## are inodes valid? + ## various elements of stat() that we might access $STAT_DEV = 1; $STAT_INODE = 2; *************** *** 194,199 **** --- 197,203 ---- -showrc show what the rc file sets, then exit. -norc don\'t load the rc file. -dorep check files with multiple hard links multiple times. + -win necessary if running under Windows 95. INLINE_LITERAL_TEXT print "Use -v -help for more verbose help.\n" unless $VERBOSE; print "This script file is also a man page.\n" unless $stripped; *************** *** 253,258 **** --- 257,266 ---- $LIST_ONLY=1,$opt{'-list'}=1, next if $arg =~/^-l(ist)?$/;## only list files + $WINDOWS=1, $USE_INODES=0, $DOREP=1, + next if $arg eq '-win'; ## running under Windows + + if ($arg =~ m/^-depth=(\d+)$/) { die qq/$0: only -depth of 0 currently supported\n/ if $1 != 0; $DESCEND_SUBDIRECTORIES=0; *************** *** 962,970 **** } ## skip things that are empty ! unless (-s _) { ! warn qq/skip (empty): $file\n/ if $WHY; ! next; } ## Note file device & inode. If -xdev, skip if appropriate. --- 970,981 ---- } ## skip things that are empty ! if (!$WINDOWS) { # -s fails for all dirs under Windows ! # or should we just put the -d test before this? ! unless (-s _) { ! warn qq/skip (empty): $file\n/ if $WHY; ! next; ! } } ## Note file device & inode. If -xdev, skip if appropriate. *************** *** 973,979 **** warn qq/skip (other device): $file\n/ if $WHY; next; } ! $id = "$dev,$inode"; ## special work for a directory if (-d _) { --- 984,990 ---- warn qq/skip (other device): $file\n/ if $WHY; next; } ! $id = "$dev,$inode" if $USE_INODES; ## special work for a directory if (-d _) { *************** *** 993,1004 **** next; } ! ## _never_ redo a directory ! if (defined $dir_done{$id}) { ! warn qq/skip (did as "$dir_done{$id}"): $file\n/ if $WHY; ! next; ! } ! $dir_done{$id} = $file; ## mark it done. unshift(@todo, $file); ## add to the list to do. next; } --- 1004,1018 ---- next; } ! if ($USE_INODES) ! { ! ## _never_ redo a directory ! if (defined $dir_done{$id}) { ! warn qq/skip (did as "$dir_done{$id}"): $file\n/ if $WHY; ! next; ! } ! $dir_done{$id} = $file; ## mark it done. ! } unshift(@todo, $file); ## add to the list to do. next; }