#!/usr/bin/perl use strict; use warnings; use MIME::Lite; use File::stat; use Time::localtime; use List::Util qw(sum); my $Accounts; my $count; my $counts; my $OUT; my $char; my @Accounts = ('AE202B01','AE202B02','AE202B03'); my $emd = `date --date '-30 min' +'%H'`; chop ($emd); $emd = "/tmp/pathtomyfiles/$emd.txt"; my %count; my $outfile = "/tmp/scripts/AESTUFF/AE202b.txt"; open (my $fh1, "-|" , "$emd") || die "Failed: $!\n" ; open ($OUT, "> $outfile") || die "Cannot open $outfile"; # temp file to which to write the formated output, if there is a match while (my $line = <$fh1>) { chomp ($line); $line =~ s/ /\n/; # $line =~ s/.*UserId1://; # $line =~ s/}.*//; # $line =~ s/,pairId:.*//; if ( $line =~ /UserId1:(\w+),pairId.*/ ) { $Accounts = $1; foreach (@Accounts) { if ($Accounts =~ /$_/ ){ foreach my $str (split /\s+/, $Accounts) { $count{$str}++; } } foreach my $str (sort keys %count) { printf "%-31s %s\n", $str, $count{$str}; } } } } #} close ($OUT);