in reply to Perl beginner here, needs a shove in the right direction.
Usually we don't write full-blown scripts if the Seeker of Perl Wisdom doesn't post any example code, but I put something together here that should get you started.
I'm not sure if glob would be faster, as I did not test it, so you can play around.
This code looks at all files located in the directory specified as the second argument to find() (recursively). If it's a file, it opens it, reads it line by line, and if it has the keyword (HELLO) at the start of line, it checks the line fields 1, 3 and 4 (after being split() on a forward slash) to ensure they are not empty. If the file contains a line starting with 'HELLO' but has at least one line without all the fields with data, it'll log to a file and continue on.
You'll need to research how to print the directory path with the file in the log (if you need it), sort out your indexing, replace your keyword etc
#!/usr/bin/perl use warnings; use strict; use File::Find; open my $log, '>', 'log.txt' or die "Can't open the log file!: $!"; find(\&check_data, "./test"); sub check_data { my $file = $_; #for clarity return if ! -f $file; open my $fh, '<', $file or die "Can't open file $file: $!"; for my $line (<$fh>){ if ($line =~ /^HELLO/){ my @parts = split(/\//, $line); for my $index (qw(1 3 4)){ if (! $parts[$index] or $parts[$index] =~ /[\s+-]/){ print $log "$file is missing data.\n"; return } } } } }
Example files:
$ cat test/hello.pl adsfasdfasdf HELLO/asdf/asdf/asdf/asdf/asdf $ cat test/testing.txt asdfasdf/dfasdf/12351234132r HELLO/asdf//////////
Output:
$ cat log.txt testing.txt is missing data.
-stevieb
EDIT: Added check for hyphen in line elems
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl beginner here, needs a shove in the right direction.
by rfromp (Novice) on Jun 16, 2015 at 21:13 UTC | |
|
Re^2: Perl beginner here, needs a shove in the right direction.
by rfromp (Novice) on Jun 17, 2015 at 17:37 UTC |