sample log,
2016-03-29 10:57:28 UTC 642 [31871] INFO node information: {"datacenter": "TEST-DC", "infraType": "saas", "service": "fusion", "extraInfo": {"systemType": "secondary-ha1", "tenantType": "sales", "tenantName": "sale1"}
I want to read "tenantName": "sale1" and the final string I need is "sale1"
tried with awk and cut inside the Perl script but didn't work out Any suggestions and/or hints will be appreciable
I got the solution with the answer from @Sobrique
used the modules JSON & List::MoreUtils
find( \&Count, $logDir);
my @uniqtotal = uniq @totCount;
$totalcount = @uniqtotal;
sub Count {
if( $File::Find::name =~m!$logDir/(.*?)/$pattern! and -f $File::Find::name ) {
my $jsonLine = `grep 'tenantName' $File::Find::name`;
if ($jsonLine ne "") {
$jsonLine =~ m/(\{.*\})/ ;
my $json_text = $1;
my $json = decode_json ( $json_text );
push @totCount, $json -> {extraInfo} -> {tenantName};
}
}
}