Hi Monks, I'm a perl newbie and need help from the experts to extract the value from the text file-1 based on value from text file-2 which is tab separated. The script is to automate my monthly internet usage report. Each customer will have separate report output similar like below.
Sample Output will be:
CUSTOMER NAME: ABC
Device_Code Port Traf_Dir Data_Usage
SWITCH Fa1_0_33 OUT 1.311
SWITCH Fa1_0_33 IN 10.716
SWITCH Fa1_0_35 OUT 50.796
SWITCH Fa1_0_35 IN 7.882
Contents of Text File 1:
200612:ABC
200905:DEF
200212:GHI
Contents of Text File 2:
200612 200612 SWITCH FastEthernet1_0_33 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 4.336 1.311
200612 200612 SWITCH FastEthernet1_0_33 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 35.435 10.716
200612 200612 SWITCH FastEthernet1_0_35 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 167.976 50.796
200612 200612 SWITCH FastEthernet1_0_35 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 26.064 7.882
200612 200612 SWITCH FastEthernet2_0_33 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200612 200612 SWITCH FastEthernet2_0_33 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200612 200612 SWITCH FastEthernet2_0_35 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200612 200612 SWITCH FastEthernet2_0_35 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200905 200905 SWITCH FastEthernet1_0_48 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 3.193 0.965
200905 200905 SWITCH FastEthernet1_0_48 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 41.499 12.549
200905 200905 SWITCH FastEthernet2_0_48 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200905 200905 SWITCH FastEthernet2_0_48 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200212 200212 SWITCH FastEthernet1_0_19 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 3.877 1.172
200212 200212 SWITCH FastEthernet1_0_19 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 0.837 0.253
200212 200212 SWITCH FastEthernet2_0_19 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200212 200212 SWITCH FastEthernet2_0_19 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
Here's my current code:
#!/usr/bin/perl
#use strict;
#use warnings;
my $cust_file="customer.txt";
my $billing_file="2010.bill";
# '<' means read only
open(CUST_DATA,'<', $cust_file) || die("Could not open file!");
#@raw_data=<CUST_DATA>;
#Done reading the file - close it
while (<CUST_DATA>) {
($CUST_ID,$CUST_NAME) = split(':',$_);
$CUST_NAME{$CUST_ID}=$CUST_NAME;
if (length($CUST_NAME)>$maxCUST_NAMElength) {
$maxCUST_NAMElength=length($CUST_NAME);
}
}
close(CUST_DATA);
# '<' means read only
open(BILL_DATA,'<', $billing_file) || die("Could not open file!");
@rawbill_data=<BILL_DATA>;
close(BILL_DATA);
Im stuck how to extract the data based on the value from first text file. :)
Thanks in advance for your help.