Re: Return text left of first tab



On Thu, 04 Mar 2010 08:15:12 -0600, Don Pich <dpich@xxxxxxxxxxxx> wrote:


After the 'my ($line) = $_;' line, I need to eliminate everything after
and including the first tab of a line in Pannaway.txt. Then send what is
left (IP Address column only) into the my@values to convert the dotted
quad ip address into a hex representation of the ip.


An assumption, this regex adds some further qualifying boundry conditions.
If learning regex's, you might want to break down the example
as an exercise.

-sln

use strict;
use warnings;

while (<DATA>)
{
if (/^((?:\d+\.?){4,6})[.:\d]*?\t.*BAS-ADSL/) {
my @ipparts = split('\.', $1);
printf ('%02x'x scalar(@ipparts) ."\n", @ipparts);
}
}
__DATA__

IP Address Name Type MAC Address
Firmware
10.21.65.252.5.4.3 ADMS.01.01 BAS-ADSL24R 00:0A:9F:00:D4:75
10.21.1.2:1280 ADMS.01.01 BAS-ADSL24R 00:0A:9F:00:D4:75
3.2.1.28
10.21.66.252 ADMS.02.01 BAS-ADSL24R 00:0A:9F:00:D4:A5
3.2.1.28
10.21.66.250 ADMS.03.01 BAS-ADSL24R 00:0A:9F:00:D4:C1
3.2.1.28
10.21.66.248 ADMS.04.01 BAS-ADSL24R 00:0A:9F:00:D4:D1
3.2.1.28
10.21.67.252 ADMS.05.01 BAS-ADSL24R 00:0A:9F:00:E5:DA
3.2.1.28

.