- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- PERL script help
Operating System - Linux
1752615
Members
5014
Online
108788
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 06:33 AM
тАО02-16-2006 06:33 AM
PERL script help
I am once again found wanting in my scripting skills.
I have few files which have data like
tran_type tran_num Suc failure percentage
abc 11 10 5 50
def 12 10 0 100
there are around 10 to 15 files like this.
I need to write a script that would read all the files and combine the data together and generate a single output file containing the summation of all the tran type and number.
Can anyone please help.
-Pat
I have few files which have data like
tran_type tran_num Suc failure percentage
abc 11 10 5 50
def 12 10 0 100
there are around 10 to 15 files like this.
I need to write a script that would read all the files and combine the data together and generate a single output file containing the summation of all the tran type and number.
Can anyone please help.
-Pat
- Tags:
- Perl
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 06:46 AM
тАО02-16-2006 06:46 AM
Re: PERL script help
Hi Pat:
Try this:
# cat perl.pl
#!/usr/bin/perl
use strict;
use warnings;
my ($key, $count);
my %data;
while (<>) {
($key,$count) = split;
$data{$key} += $count;
}
foreach $key (sort keys %data) {
print "$key $data{$key}\n";
}
Run as:
./perl.pl file1 file2 file3 ...
Regards!
...JRF...
Try this:
# cat perl.pl
#!/usr/bin/perl
use strict;
use warnings;
my ($key, $count);
my %data;
while (<>) {
($key,$count) = split;
$data{$key} += $count;
}
foreach $key (sort keys %data) {
print "$key $data{$key}\n";
}
Run as:
./perl.pl file1 file2 file3 ...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 06:56 AM
тАО02-16-2006 06:56 AM
Re: PERL script help
And of course you'd extent that to the other fields:
($key,$count,$suc,$fail) = split;
$data{$key} += $count;
$suc{$key} += $suc;
:, because you woudl have to do a weighted calc.
Just recalculate if needed after reading all.
Hein.
($key,$count,$suc,$fail) = split;
$data{$key} += $count;
$suc{$key} += $suc;
:, because you woudl have to do a weighted calc.
Just recalculate if needed after reading all.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 06:58 AM
тАО02-16-2006 06:58 AM
Re: PERL script help
[ooop, wrong button. Moderator, please delete prior reply]
And of course you'd extent that to the other fields:
($key,$count,$suc,$fail) = split;
$data{$key} += $count;
$suc{$key} += $suc;
:
print ... $suc{$key}...
I woudl not add the percentages, because you would have to do a weighted calc.
Just recalculate if needed after reading all.
Hein.
And of course you'd extent that to the other fields:
($key,$count,$suc,$fail) = split;
$data{$key} += $count;
$suc{$key} += $suc;
:
print ... $suc{$key}...
I woudl not add the percentages, because you would have to do a weighted calc.
Just recalculate if needed after reading all.
Hein.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP