HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Generate consolidated Report
Operating System - Linux
1829108
Members
13608
Online
109986
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
Forums
Discussions
Discussions
Discussions
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
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
10-18-2005 04:58 AM
10-18-2005 04:58 AM
Generate consolidated Report
Hi,
I have some reports like the one attached along with this thread. I need to write a script which will create a master report with the combined data from all the reports.
For instance in the attached report, I have
ID Attempts Success Failure
11 20 18 2
I need to add Attempts,Sucess, Failure of all the ID=11 from the different files and report to the master file. Similiarly, I need to report the other IDs also.
Also,I need to read the input file names from a configuration file.
Please help. Either PERL or UNIX script would do.
Thanks,
Rahul
I have some reports like the one attached along with this thread. I need to write a script which will create a master report with the combined data from all the reports.
For instance in the attached report, I have
ID Attempts Success Failure
11 20 18 2
I need to add Attempts,Sucess, Failure of all the ID=11 from the different files and report to the master file. Similiarly, I need to report the other IDs also.
Also,I need to read the input file names from a configuration file.
Please help. Either PERL or UNIX script would do.
Thanks,
Rahul
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2005 05:24 AM
10-18-2005 05:24 AM
Re: Generate consolidated Report
Hi
this assumes all filenames *.txt and id 2 digits only.
Adapt when required.
###########################################
#!/bin/sh
grep ^[0-9][0-9]" " *.txt | cut -d":" -f2 | sort | awk '{
if($1==oldid) {
attempts+=$2;
success+=$3;
failure+=$4;
}
else {
print oldid,attempts,success,failure;
oldid=$1;
attempts=$2;
success=$3;
failure=$4;
}
}
END{print oldid,attempts,success,failure;}'
Regards
Jean-Luc
this assumes all filenames *.txt and id 2 digits only.
Adapt when required.
###########################################
#!/bin/sh
grep ^[0-9][0-9]" " *.txt | cut -d":" -f2 | sort | awk '{
if($1==oldid) {
attempts+=$2;
success+=$3;
failure+=$4;
}
else {
print oldid,attempts,success,failure;
oldid=$1;
attempts=$2;
success=$3;
failure=$4;
}
}
END{print oldid,attempts,success,failure;}'
Regards
Jean-Luc
fiat lux
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2005 10:03 PM
10-18-2005 10:03 PM
Re: Generate consolidated Report
Hi,
try the following:
awk 'NR==1 {nfield=NF;header=$0;next}
/^[0-9]/ && NF==nfield {ids[$1]=$1;for(i=2;i<=NF;i++) f[$1,i]+=$i }
END {print (header,"\n")
for (id in ids) {printf(id); for(i=2;i<=nfield;i++) printf("\t%s",f[id,i]); printf("\n")}}' file1 .... filen
This will ignore lines not having the identical number of fields of the first header.
mfG Peter
try the following:
awk 'NR==1 {nfield=NF;header=$0;next}
/^[0-9]/ && NF==nfield {ids[$1]=$1;for(i=2;i<=NF;i++) f[$1,i]+=$i }
END {print (header,"\n")
for (id in ids) {printf(id); for(i=2;i<=nfield;i++) printf("\t%s",f[id,i]); printf("\n")}}' file1 .... filen
This will ignore lines not having the identical number of fields of the first header.
mfG Peter
The Universe is a pretty big place,
it's bigger than anything anyone has ever dreamed of before.
So if it's just us, seems like an awful waste of space, right?
Jodie Foster in "Contact"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2005 10:30 PM
10-18-2005 10:30 PM
Re: Generate consolidated Report
You can try with PERL scripting as,
#!/usr/contrib/bin/perl
#master.pl
$i=0;
while (<>)
{
($id,$attempt,$success,$failure)=split;
$I_arr[$id]=$id;
$A_arr[$id]+=$attempt;
$S_arr[$id]+=$success;
$F_arr[$id]+=$failure;
}
foreach $var (@I_arr)
{
if ($var !~ /^$/)
{
printf "ID= $I_arr[$var] Attempt = $A_arr[$var] Success = $S_arr[$var] Failure = $F_arr[$var] \n";
}
}
# perl master.pl > master.pl
will make it.
hth.
#!/usr/contrib/bin/perl
#master.pl
$i=0;
while (<>)
{
($id,$attempt,$success,$failure)=split;
$I_arr[$id]=$id;
$A_arr[$id]+=$attempt;
$S_arr[$id]+=$success;
$F_arr[$id]+=$failure;
}
foreach $var (@I_arr)
{
if ($var !~ /^$/)
{
printf "ID= $I_arr[$var] Attempt = $A_arr[$var] Success = $S_arr[$var] Failure = $F_arr[$var] \n";
}
}
# perl master.pl > master.pl
will make it.
hth.
Easy to suggest when don't know about the problem!
- Tags:
- Perl
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.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP