Hi,
I want to search for a string in a text file and print the summary of total count of how many of it exists in the file.
For example, here my text in the file from which I want to count how many times 'Status: Updated' and 'Status: Created' occured each. Item UPC: 111, Desc: ALMOST, Price: 0, Status: Updated
Item UPC: 112, Desc: CRAZY BALL, Price: 0, Status: Updated
Item UPC: 112, Desc: DVD, Price: 0, Status: Updated
Item UPC: 113, Desc: dvd, Price: 0, Status: Updated
Item UPC: 114, Desc: CARS, Price: 8.25, Status: Created
Item UPC: 115, Desc: CARS RACE, Price: 0.01, Status: Created
Item UPC: 116, Desc: BOXES, Price: 49.99, Status: Created
So, the result/summary to be printed as:
Total Status: Updated = 4, Status: Created = 3
Any way to do this please?
Thanks in advance.
This is what I tried, but getting compilation errors. So, not working. Any alternative method to achieve this please:
I want to search for a string in a text file and print the summary of total count of how many of it exists in the file.
For example, here my text in the file from which I want to count how many times 'Status: Updated' and 'Status: Created' occured each. Item UPC: 111, Desc: ALMOST, Price: 0, Status: Updated
Item UPC: 112, Desc: CRAZY BALL, Price: 0, Status: Updated
Item UPC: 112, Desc: DVD, Price: 0, Status: Updated
Item UPC: 113, Desc: dvd, Price: 0, Status: Updated
Item UPC: 114, Desc: CARS, Price: 8.25, Status: Created
Item UPC: 115, Desc: CARS RACE, Price: 0.01, Status: Created
Item UPC: 116, Desc: BOXES, Price: 49.99, Status: Created
So, the result/summary to be printed as:
Total Status: Updated = 4, Status: Created = 3
Any way to do this please?
Thanks in advance.
This is what I tried, but getting compilation errors. So, not working. Any alternative method to achieve this please:
Code:
open my $fh, '>', 'Product_Import_Log.txt');
my %count;
while (<$fh>)
{
if (/Status:\s+(\w+)/)
{
$count{$1}++;
}
}
print 'Totals: ', (\%count);