Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, i am new to Perl and am confused on an issue. I have a script that is using two files as input. One contains backup jobnames and the other contains a list of server names. My goal is to use the server names to grep backup jobnames. The script works fine the first time around but does not grep the second backup job (verified it exists). Here is my Perl code:
#!/usr/bin/perl use warnings; use strict; system "autorep -J NB% | egrep -v \"Job Name|___\" | awk '{print \$1}' + | sed '/^\$/d' | sort > NB_JIL.txt"; chomp(my @server_names = <>); open NB_FILE, '<', "/users/home/mkar/Perl_scripts/NB_JIL.txt" or die " +Couldn't open Netbackup file!"; my $iteration_number = 1; for my $backup_job (@server_names) { print ":$iteration_number:\n"; print "$backup_job\n"; print (grep /$backup_job/, <NB_FILE>); $iteration_number ++; } close NB_FILE or die "Couldn't close the file properly!"
This is what it produces:
What am I doing wrong? Thank you in advance !> ./test.pl test.txt :1: puccini NB_ISA_SNOH_puccini_DB_diff NB_ISA_SNOH_puccini_DB_full :2: cgndsdr4 >
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with for loop
by BrowserUk (Patriarch) on Sep 12, 2013 at 02:22 UTC | |
|
Re: Help with for loop
by Athanasius (Archbishop) on Sep 12, 2013 at 02:30 UTC | |
|
Re: Help with for loop
by NetWallah (Canon) on Sep 12, 2013 at 05:29 UTC | |
|
Re: Help with for loop
by Laurent_R (Canon) on Sep 12, 2013 at 06:46 UTC | |
|
Re: Help with for loop
by Anonymous Monk on Sep 12, 2013 at 02:20 UTC | |
|
Re: Help with for loop
by uday_sagar (Scribe) on Sep 12, 2013 at 09:16 UTC |