Hi all, I'm trying to do something fairly simple but can't figure out whats going wrong. I'm running NBTSTAT -a on a load of IP addresses - supplied from a file NBT.CSV -It's a windoze program which gives fairly verbose output - What I'm trying to get is the first 15 characters of each line with no duplicates in comma delimited form. A fairly simple text processing job I thought - I figured without me having left my brain at home today.
The code is as follows
#!c:\perl\bin\perl -w
open(NB, "nbt.csv")|| die"Cant open input file nbt.csv";
# NBT.CSV simply contains ip addresses - one per line
while(<NB>)
{undef $line;
chomp $_;
$line="$_".",";
@nbtstat = `nbtstat -a $_`;
$len=@nbtstat;
for ($j=0; $j<$len;$j++)
{$short=substr($nbtstat[$j],0,15);
chomp $short;
unless ($line=~m/$short/)
{$line=$line.",".$short;}
}
print "$line\n";
}
close(NB);
What I get is like this - first line is correct, second line is missing the ip address at the beginning - I cant figure out why?
1.1.1.1,,Host not found.
, Name ,---------------,Registered Regi,WS12345678901,USER1,MAC Address = 0
The text this is produced from is like this
C:\Perl>nbtstat -a 1.1.1.1
Host not found.
C:\Perl>nbtstat -a 1.1.1.2
NetBIOS Remote Machine Name Table
Name Type Status
---------------------------------------------
WS12345678901 <00> UNIQUE Registered
EUROPE-AFRICA <00> GROUP Registered
ws12345678901 <20> UNIQUE Registered
WS12345678901 <03> UNIQUE Registered
USER1 <03> UNIQUE Registered
MAC Address = 00-06-C7-E6-D8-36
Any ideas or donations of money would be gratefully received. Thanks Andrew
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.