Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Snooping through files

by Simplicus (Monk)
on Apr 14, 2000 at 17:57 UTC ( [id://7621]=CUFP: print w/replies, xml ) Need Help??

I was recently given the task of combing through 16,000 + files looking for those that were created by one employee. The only flag (since this is a Win95 peer/peer network we're talking about)(yeah, I know, but it pays the rent . . .:-), is the employee number buried in the file. The file is delimited by the character "³" (\xB3). The employee number in this case is 400. Here's the code I used:
#!/usr/bin/perl -w { $bucket = 0; $count = 1; open (LOGFILE, ">>log.txt") || die "Can't open file: $!"; while ($infile = glob("/biz/employee/data/*")) { open (INFILE, $infile) || die "Can't open file: $!"; while (<INFILE>) { print "$count : "; if ($_ =~ /³400³/) { $bucket++; print "Found Employee $bucket times.\n"; print LOGFILE ("$_\n"); } else { print "\n"; } $count++; } } print "Finished. Found Employee $bucket time in $count files. \n"; }
I know it's more of a "mundane use for Perl", but it was my first truly fuctional Perl script, and using it I was able to hand my boss the list he wanted in a day instead of longer. As far as I'm concerned, that's cool. Simplicus.

Replies are listed 'Best First'.
RE: Snooping through files
by turnstep (Parson) on Apr 15, 2000 at 21:21 UTC
    Why is count incremented at every line? The final print statement actually reports the total number of lines searched, not the total number of files. It also seems to output a line count to STDOUT - which could get messy if you are searching 16,000+ files... You proabably need to move the statements with count outside the inner while loop. (unless each file is exactly one line long, in which case it doesn't make a difference)
      sorry, I should have been a bit more descriptive. each file is one line long. The fields are delimited by the character ³, and the file ends with a "\n". The goal was to merge the files (each a line), and spit out an excel-readable text file. I worked really well.
RE: Snooping through files
by Simplicus (Monk) on Apr 14, 2000 at 22:59 UTC
    Of course, in My shop, we run Linux :-) and Samba the records in . . . S-

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://7621]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2025-07-09 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.