Perl - save results to output file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl - save results to output file.
# 1  
Old 02-10-2011
Perl - save results to output file.

Can any one please help, the code works...I want the output of $result to be saved in an output.txt file which is lcoated in c:\\temp\\output.txt.


Code:
 
$filepath="C:\\temp\\ip.txt";
open (HOSTLIST,"$filepath"); 
@hosts=(<HOSTLIST>); 
 
foreach $host(@hosts) 
{ 
  $results = `nslookup $host`; 
  chomp ($host); 
  print ("Results for $host:\n"); 
  print ("$results\n\n");
} 
close (HOSTLIST);


Last edited by Scott; 02-10-2011 at 02:43 PM.. Reason: Quote tags -> Code tags
# 2  
Old 02-10-2011
Code:
use strict;
use warnings;

my $filepath = "ip.txt";
my $outfile  = "output.txt";

open (HOSTLIST, "$filepath") || die "ERROR: opening $filepath\n";
my @hosts = <HOSTLIST>;
close HOSTLIST;

open (OUTFILE, ">> $outfile") || die "ERROR: opening $outfile\n";

foreach my $host(@hosts)
{
   my $results = `nslookup $host`;
   chomp ($host);
   print OUTFILE "Results for $host:\n";
   print OUTFILE "$results\n\n";
}

close OUTFILE;

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Save value from output of Corestat and save in a list for each core

I am trying to modify the "corestat v1.1" code which is in Perl.The typical output of this code is below: Core Utilization CoreId %Usr %Sys %Total ------ ----- ----- ------ 5 4.91 0.01 4.92 6 0.06 ... (0 Replies)
Discussion started by: Zam_1234
0 Replies

2. Shell Programming and Scripting

Save output into file bash scripting

Hi there. i have created a program that in the end it will give output like this 1 2 3 4 5 10 9 8 7 6 11 12 13 14 15 .............. 17 i wonder how to save the output into a single string and into a file. i.e 1 10 11 12 9 2 3 8 13 14 7 4 5 6 15 17 (in this order,... (3 Replies)
Discussion started by: shdin271
3 Replies

3. Shell Programming and Scripting

Save output to file - inside a script ?

I'm using the following script to check cisco router health and I'd like to save output to a file, vty_runcmd.sh > /check/check-cisco-health script works and output is saved to a file. However using it in crontab file is created but output is not printed inside it. In crontab, */5 * * * *... (4 Replies)
Discussion started by: marmellata
4 Replies

4. Shell Programming and Scripting

[Shell/Perl(?)] Prepending timestamps to console output & writing results to a file

I do a lot of TSM work and I embarked on what I thought would be an easy task, and I'd be very happy for any input to save the pounding my keyboard is receiving :] By default, the output of TSM's console has no timestamping, making it hard to sort through accurately. This puts my console into... (5 Replies)
Discussion started by: Vryali
5 Replies

5. Shell Programming and Scripting

PERL Scripting: Diff 2 files and save output to file3

Hi, I need to create a script to compare 2 files and store the output in a 3rd file. This is how I do manually, but since I need to do this for about 150 files every week, I am trying to automate it using perl. diff -u file1 file2 > file3.patch For my script, - I have 2 files... (4 Replies)
Discussion started by: script2010
4 Replies

6. Shell Programming and Scripting

Way to save output result of a program into another new file...

Does anybody know any alternative way to save output result of a program into another new file? I got try the command below: program_used input_file > new_output_file program_used input_file >> new_output_file Unfortunately, both the ">" and ">>" is not work at this case to save the output... (6 Replies)
Discussion started by: patrick87
6 Replies

7. Shell Programming and Scripting

Save cURL verbose output to file or do it like browser "save as.."

hi there ! i have exactly the same problem like this guy here https://www.unix.com/shell-programming-scripting/127668-getting-curl-output-verbose-file.html i am not able to save the curl verbose output.. the sollution in this thread (redirecting stderr to a file) does not work for me.... (0 Replies)
Discussion started by: crabmeat
0 Replies

8. Shell Programming and Scripting

let curl output to stdout AND save to a file

hello hackers. i have a curl process running as cgi directly pushing stdout to the client. but i want to additionally save that stream to a file at the same time. any directions madly welcome. thanks in advance (3 Replies)
Discussion started by: scarfake
3 Replies

9. Solaris

terminal output - save to file?

I have a window open on my ultra 10 - a terminal window connecting to a server. Is there any way I can log all output to this window to a log file on my ultra 10 ? (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question