#!/usr/bin/perl use strict; # Grep a user line OUT of a file, given a list of names, from another file # psuedo code: # if file1 contains a name from file2, skip the line # if file1 does NOT contain a name from file2, print the line. # # I am using this to determine a list of # accounts that should be present, or not, on a server my @users; my $file1=$ARGV[0]; my $file2=$ARGV[1]; open FILE1, "<$file1" or die "Cannot open $file1: $!\n"; my @file1=; close FILE1; open FILE2, "<$file2" or die "Cannot open $file2: $!\n"; my @file2=; close FILE2; # Create @users array my @out; foreach my $line (@file2) { if ($line =~ /#/) { @out=split /\s+/,$line; push @users,$out[1]; } } LINE: foreach my $line (@file1) { USER: foreach my $user (@users) { print "is $user on $line"; if ($line =~ /$user/i) { print "YES $user is on $line ; next LINE\n"; next LINE; } else { # This is where I get into trouble. I'm thinking I need to set # some kind of flag or something, because otherwise I will exhaust # the total list of users and will either get false positives # or skip them all together... print "nope... next USER\n"; next USER; } } }