gzayzay has asked for the wisdom of the Perl Monks concerning the following question:
Today was a beautiful day watching the Solar eclipse on NASA TV. However, let me get to the point. I am trying to write a script that will check a file to see if the first 20 lines does not contain the word "DAVE". While searching for DAVE, I will like for the script to ignore case sensitivity i.e Dave and DAVE should be consider the same. If the first 20 lines of the file does not have dave, I will like to print the path of that file to a folder I called "input". I have used the find function to generate the paths to every files that I will love to search and store it in a file called "output". My problem is, I am not able to return the name of the file if it does not contain dave and i have not been able to make the search case insensitive.
Therefore, I am kindly asking any monk to help me. Thanks for your assistance.
use strict; use File::Find; my $count; my $path = "C:/hello/"; my $output = $path."Output.txt"; my $input = $path."Input.txt"; START: print ("Enter the name of your file >> "); chomp (my $name = <STDIN>); if(length($name)==0) { print (STDERR "\nYour did not respond!!\n"); goto START; } else { my $spath = $path.$name; open(FM, ">$output") && open(AM, ">$input") || die ("Cannot open, +$!\n"); find(\&search, "$spath"); close FM; open(SW, $output)||die ("Cannot open, $!\n"); while(<SW>) { my $flag = 1; chomp; if (open(ETA, $_)) { $count = 0; while(<ETA>) { foreach($_){$count++;}; if (($_ ne "Dave") && ($count <= 20)) { $flag = 0; } } if ($flag == 0) { #I am trying to print the name of the file containg "D +ave" in the first 20 lines print (AM "$_\n"); } } else { die ("Cannot open [$_], $!\n"); } }close AM; close SW; } sub search { if (((/\.c/)&&(!(/\.com/)))|(/\.h/)|(/\.pr/)) { print (FM "$File::Find::name\n"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding names in files
by davidrw (Prior) on Mar 29, 2006 at 17:28 UTC | |
by gzayzay (Sexton) on Mar 29, 2006 at 17:36 UTC | |
by davidrw (Prior) on Mar 29, 2006 at 17:39 UTC | |
|
Re: Finding names in files
by ww (Archbishop) on Mar 29, 2006 at 17:28 UTC | |
by gzayzay (Sexton) on Mar 29, 2006 at 17:32 UTC | |
|
Re: Finding names in files
by duff (Parson) on Mar 29, 2006 at 17:42 UTC | |
by gzayzay (Sexton) on Mar 29, 2006 at 18:23 UTC | |
by SamCG (Hermit) on Mar 29, 2006 at 18:44 UTC | |
|
Re: Finding names in files
by zer (Deacon) on Mar 29, 2006 at 17:32 UTC |