I have a log file in a table structured form like this(below) and want to edit same send-id column in it. I new to perl and tried but not able to get what I want.
Code send_id dest_id
AW 96 45
BX 65 96
Now here I have to edit that send_id column id's to the names (like 96 = Alex and 65= James) and regenerate the log file like the below format[enter image description here][2].
Code send_id dest_id
AW Alex 45
BX James 96
I did till here but not getting the desired output.I am reading line by line. I am getting like this
Code send_id dest_id
AW Alex 45
James
Can anyone tell me how to do it?
Thank You.
#!/usr/bin/perl
use warnings;
use strict;
my $log_file = "/home/ajay/Desktop/log.log";
open(Log1,"<$log_file") or die ("Could not open");
open(Log2,">$log2.pl");
while ($a=<Log1>) {
if ($a =~ /65/){
$a = "James";
print Log2"$a\n";
}
else {
print Log2"$a";
}
}
close Log2;
close Log1;