Piercer has asked for the wisdom of the Perl Monks concerning the following question:
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
, 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
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.#!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);
, 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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Text processing question - strange output
by amelinda (Friar) on Nov 20, 2001 at 22:55 UTC | |
Re: Text processing question - strange output
by mkmcconn (Chaplain) on Nov 21, 2001 at 00:59 UTC | |
Re: Text processing question - strange output
by frankus (Priest) on Nov 20, 2001 at 22:56 UTC | |
Re: Text processing question - strange output
by buckaduck (Chaplain) on Nov 20, 2001 at 23:28 UTC | |
Re: Text processing question - strange output
by gryphon (Abbot) on Nov 20, 2001 at 23:52 UTC |
Back to
Seekers of Perl Wisdom