- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: totalling columns in a script
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
05-14-2003 05:12 PM
05-14-2003 05:12 PM
Here is the output.
D E V I C E G R O U P S
Num of Num of Num of
Name Type Valid Symmetrix ID Devices GK's BCV's
goanna1_rdf RDF2 Yes 000285502576 18 0 18
koala1_rdf RDF1 Yes 000285502576 70 0 0
snake11_rdf RDF1 Yes 000285502576 26 0 0
beaver4_rdf RDF1 Yes 000285502576 5 0 0
trouser1_meta REGULAR Yes 000285502576 1 0 0
monster1_meta1 REGULAR Yes 000285502576 1 0 1
beaver2_reg REGULAR Yes 000285502576 4 0 0
I can total one column using:
$ awk 'BEGIN {total +=5;}
> END {print "Total ",total}' inputfile >outputfile
When I try to use a similar method it gives a strange total
$ awk '{F5=F5+$5;F6=F6+$6;F7=F7+$7};END {print F5,F6,F7}'inputfile
3787 458 03787 458 0
What I really want is totals for each of the last three columns with the numbers appearing underneath.
AWK would be preferable but any ideas to solve the problem will get you points.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 05:23 PM
05-14-2003 05:23 PM
Re: totalling columns in a script
COL6=0
COL7=0
cat file | while read a b c d e f g
do
COL5=$(($e+$COL5))
COL6=$(($f+$COL6))
COL7=$(($g+$COL7))
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 06:11 PM
05-14-2003 06:11 PM
Re: totalling columns in a script
I want to append to the same input file.
$ awk '{t1 +=$5;t2 +=$6;t3 +=$7}
> END {print "Total "t1 ,t2 ,t3}' input file >>inputfile
Thanks Michael for your suggestion but it gives an error:
C+0: bad number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 06:23 PM
05-14-2003 06:23 PM
Re: totalling columns in a script
$ awk '{F5=F5+$5;F6=F6+$6;F7=F7+$7;} END {print "total:", F5,F6,F7}' inputfile
You got a bit of syntax problem in your original awk statement. I did not test this but I think it should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 06:30 PM
05-14-2003 06:30 PM
Re: totalling columns in a script
I had already worked that part out. I have since got it to work using this, but there must be a better way to format using spaces, which is what I've done.
cat /tmp/myfile| awk '{t1 +=$5;t2 +=$6;t3 +=$7}
END {printf("Total %d %d %d\n",t1,t2,t3)}' >>/tmp/myfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 07:34 PM
05-14-2003 07:34 PM
Re: totalling columns in a script
I don't care if I have to use something else. ... perl ... ? please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 08:12 PM
05-14-2003 08:12 PM
Re: totalling columns in a script
$ cat /tmp/... END {printf("Total 5%d8%d10%d\n",t1,t2,t3)}' .....
and you would get this output.
Total<4 spaces>125<7 spaces>0<9 spaces>19
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 08:50 PM
05-14-2003 08:50 PM
Re: totalling columns in a script
That does not help, it now prints my total line as
Total 5125801019
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2003 09:07 PM
05-14-2003 09:07 PM
Solutione.g.
cat file | awk '{t1 +=$5;t2 +=$6;t3 +=$7}
END {printf("Total %50d %8d %8d\n",t1,t2,t3)}' >>file
The padding for the spacing of the numbers has to be after the % sign not before.
Regards
Michael
"When I have trouble spelling, it's called fat finger syndrome"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2003 02:12 AM
05-15-2003 02:12 AM
Re: totalling columns in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2003 02:58 AM
05-15-2003 02:58 AM
Re: totalling columns in a script
perl -ape '{$a+=$F[4];$b+=$F[5];$c+=$F[6]}END{printf("Total %50d %8d %8d\n",$a,$b,$c)}' yourfile
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2003 06:20 AM
05-16-2003 06:20 AM
Re: totalling columns in a script
awk -f file.awk filename > outputFile
I think this will generate what you want.
= Mike =
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2003 01:45 PM
05-18-2003 01:45 PM