Operating System - HP-UX
1832925 Members
2822 Online
110048 Solutions
New Discussion

Re: shell script awk help

 
kholikt
Super Advisor

shell script awk help

 
abc
2 REPLIES 2
Steven Sim Kok Leong
Honored Contributor

Re: shell script awk help

Hi,

Off my head, a simple perl script can go something like this:

=======================================
#!/usr/bin/perl

open (FILE, "nnm.txt");

while ()
{
if (/HOSTNAME: (.*)/)
{
host=$1;
}
elsif (/NUMBER OF INTERFACES:(\d+)/)
{
int=$1;
}
elsif (/IP ADDR: (.*)/)
{
ipaddr=$1;
# even if there are multiple IP addresses, the $host, $int will still be correct.
print STDOUT "$host,$int,$ipaddr\n";
}
}

close (FILE);
=======================================

Hope this helps. Regards.

Steven Sim Kok Leong
Steven Sim Kok Leong
Honored Contributor

Re: shell script awk help

Hi,

I just noticed that I have missed out the $ sign for the variable. It should thus be:

$host="$1";
$int="$1";
$ipaddr="$1";

instead of:

host=$1;
int=$1;
ipaddr=$1;

Hope this helps. Regards.

Steven Sim Kok Leong