#!/usr/bin/perl

if ($#ARGV != 1) {
    print ("\n    Usage: Converter_NLANR.pl <original log filename> <result filename>\n\n");
    exit;
}

open(FILE_RD,@ARGV[0]) || die("Could not open original log file '@ARGV[0]'!\n");
open(FILE_WR,">@ARGV[1]") || die("Could not open result file '@ARGV[1]'!\n");

$count = 1;
while ($line=<FILE_RD>) {
    @fields=split(/ +/, $line);

    $url = @fields[6];
    if ( $mapping{$url} == 0 ) {
        $mapping{$url} = $count++;
    }

    print FILE_WR "$mapping{$url} "; # URL = "server" + "path"
    print FILE_WR "0 ";              # omit "path"
    print FILE_WR "@fields[4] ";     # size
    print FILE_WR "@fields[1] ";     # cost
    print FILE_WR "0 ";              # omit "last_modify"
    print FILE_WR "@fields[0]\n";     # timestamp
}

close(FILE_RD);
close(FILE_WR);

