#!/usr/bin/perl use strict; use Data::Dumper; # Grep a user OUT of a file, given a list of names, likely 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 on the partners server # that, *maybe*, shouldn't be on there any more. my @users; my %lines; my $file1=$ARGV[0]; my $file2=$ARGV[1]; open FILE1, "<$file1" or die "Cannot open $file1: $!\n"; # Hasherize it!!! foreach my $line () { chomp($line); $lines{$line}=0; } close FILE1; # Create @users array open FILE2, "<$file2" or die "Cannot open $file2: $!\n"; foreach my $line () { if ($line =~ /#/) { my @out=split /\s+/,$line; push @users,$out[1]; } } close FILE2; foreach my $key (keys(%lines)) { foreach my $user (@users) { if ($key =~ /$user/i) { $lines{$key}++; } } } print "List of users not authorized to have an account\n"; foreach my $key (sort keys(%lines)) { if ($lines{$key} <= 0) { print "$key\n"; } } print "\nList of users authorized to have an account\n"; foreach my $key (sort keys(%lines)) { if ($lines{$key} > 0) { print "$key\n"; } }