Need help with perl script with a while loop reading file
Good morning, I appreciate any assistance that I can get from the monks out there. I am able to get this to work for me so that I can do a hostname lookup if I only specify one hostname in the script. What I want to do is have a file with hostnames and do lookups for each name in the file. Here is the code that works, and the output:
This is the output you get when you run it:
So now taking it a step further, I want to check a whole file of names. This is the code I have, but it's not working. Can someone please help and let me know where I went wrong?
---------- Post updated at 08:25 AM ---------- Previous update was at 08:01 AM ----------
I found the mistake.
Here is the updated code that works:
Here is the sample output:
Quote:
Found an A record for google.com: 74.125.226.192
Found an A record for google.com: 74.125.226.193
Found an A record for google.com: 74.125.226.201
Found an A record for google.com: 74.125.226.199
Found an A record for google.com: 74.125.226.197
Found an A record for google.com: 74.125.226.194
Found an A record for google.com: 74.125.226.195
Found an A record for google.com: 74.125.226.206
Found an A record for google.com: 74.125.226.196
Found an A record for google.com: 74.125.226.198
Found an A record for google.com: 74.125.226.200
Found an A record for perl.org: 207.171.7.53
Found an A record for perl.org: 207.171.7.43
Found an A record for yahoo.com: 98.139.183.24
Found an A record for yahoo.com: 98.138.253.109
Found an A record for yahoo.com: 206.190.36.45
HI
I need to read each line (test.txt) and store it in a array (@test)
How to do it in perl.
Suppose i have a file test.txt. I have to read each line of the test.txt file and store it in a array @test. How to do it in perl.
Regards
Harikrishna (3 Replies)
I am reading a file using While loop
while <FILE>
{
$_ = <FILE>;
process data...
}
I would like to quit reading the file once I encounter a String pattern. How do i do it.
is it
if (/SUMMARY/)
{
last;
}
I am having problems with uninitialized value in pattern... (1 Reply)
Hi,
I am building a script to grep for a string in all the files from a folder and display the results.
I am reading the files one by one by placing the names in other file using while loop
my code is as below
while read inp
do
chk=`grep -c "$str" $pth/$inp`
... (2 Replies)
Hi Everyone, I am very new to perl, but came across a situation wherein I have to read a c++ header file and write the datatype, its identifier and also the length to an excel file. There can be other header files, in the directory but I should browse through the file which has only "_mef:" string... (9 Replies)
Hi!
I have a need to do this in Perl.
script.pl -config file
The script would be doing a wget/LWP on a URL which is defined in the config file.
So when I run the script it should return either one of these conditions -
1) OK with exit status 0.
Should also print "wget URL"
2)... (6 Replies)
Need perl script, data file will be csv format.
I have text file contains 2 colums.
Filename Foldernumber
aaaa 13455
bbbb 23465
cccc 26689
I have two location 1. files present and 2. folders present. I need to search for file and folder if folder... (3 Replies)
Hi,
i need a perl script which reads the file, content is given below. and output in new file.
TARGET DRIVE IO1 IO2 IO3 IO4 IO5
------------ --------- --------- --------- --------- ---------
0a.1.8 266 236 ... (3 Replies)
I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error.
File abc.ini content
# database name
DBname =UATBOX
my $ex_stat;
my $cmd_output;
$ex_stat = "\Qawk '/^DBname/{print... (2 Replies)
Hi,
I am writing in a file through cat command. This file will contain the path of file along with filename. e.g. /home/user/folder1/folder2/filename.txt
There might be very large number of this path in same file like say 140
when I try to run while command:
while read -r file
do
//command... (8 Replies)
Hello All,
I have two files with me file1.txt and file2.txt
file1.txt has:
333
222
111
file2.txt has
ccc
bbb
aaa
ccc is related to 333 only, bbb is related to 222 only and aaa is related to 111 only.
I have to get the values from each of the file and pass them in the URL... (3 Replies)