cbtshare has asked for the wisdom of the Perl Monks concerning the following question:

Hello All, I am getting a list of ipaddresses from aws into an array then search if that ip is already in the file, if not insert it, but having a bit of trouble with the grep command, I also tried sed but the logic doesnt work, am I doing it wrong? I don't want to send the command results to a file, then open and read that file, search that way for the ip, then input input into another file. So at first awsList is blank, then command runs, nothing should be found, so it inserts all the ips, then on subsequent runs if it finds ip in awsLists, it does nothing

#!/usr/bin/perl use warnings; use strict; my $awsLists = '/ansible/awsLists'; my @command; @command=`aws ec2 describe-instances --filters "Name=instance-state-na +me,Values=running" | grep PrivateDnsNam$ foreach my $line (@command) { chomp($line); if (grep /$line/, $awsLists ) { print "found\n"; } else { print "not found\n"; system qq{ echo "$line" >> "$awsLists"}; } }
if ( ! `sed "/$line/p" $awsLists` ) { print "not found\n"; system qq{ echo "$line" >> "$awsLists"}; } else { print "found\n"; }

I also tried grep -Fxq $line $awsLists