Sponsored Content
Top Forums Shell Programming and Scripting Print sum and relative value of the sum Post 302435821 by saint2006 on Thursday 8th of July 2010 09:08:18 AM
Old 07-08-2010
Print sum and relative value of the sum

Hi

i data looks like this:

Code:
student 1 
Subject1 45 55 
Subject2 44 55 
Subject3 33 44 
//
student 2 
Subject1 45 55 
Subject2 44 55 
Subject3 33 44

i would like to sum $2, $3 (marks) and divide each entry in $2 and $3 with their respective sums and print for each student as $4 and $5.

desired output:

Code:
Student 1
Subject1	45	55	0.368852459	0.357142857
Subject2	44	55	0.360655738	0.357142857
Subject3	33	44	0.270491803	0.285714286
//
student 2 
Subject1	45	55	0.368852459	0.357142857
Subject2	44	55	0.360655738	0.357142857
Subject3	33	44	0.270491803	0.285714286


Please help me with awk or perl

Many thanks in advance

Last edited by radoulov; 07-08-2010 at 10:10 AM.. Reason: Pease use code tags!
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

2. Shell Programming and Scripting

loop + sum + print using awk

Hi, I am unable sum of each column in the loop usng awk command. Awk is not allowing the parameters in the command. i am facing the below error. awk: 0602-562 Field $() is not correct. Source file abc.txt 100,200,300,400,500,600,700,800,900 101,201,301,401,501,601,701,801,901 ... (1 Reply)
Discussion started by: number10
1 Replies

3. UNIX for Dummies Questions & Answers

Getting the sum

I am trying to get the sum of the first column of a file. When I use the same method for other files it works just fine... for some reason for the file below it gives me an error that I don't understand... I tried looking at different lines of the file and tried different things, but I still... (7 Replies)
Discussion started by: cosmologist
7 Replies

4. Shell Programming and Scripting

sum from ls -al |awk '{print $5}'

// AIX 5.3 & AIX 6.1 ls -al |awk '{print $5}' This gives each file's size in byte. I need to get: - the sum of all files in Giga bytes with loop. - excluding the size of directories (ls -al returns the size of directories). There are hundreds and thousands of files, so summing up... (8 Replies)
Discussion started by: Daniel Gate
8 Replies

5. Shell Programming and Scripting

Search two patterns using awk to print the variable sum

Coins.txt: gold 1 1986 USA American Eagle gold 1 1908 Austria-Hungary Franz Josef 100 Korona silver 10 1981 USA ingot gold 1 1984 Switzerland ingot gold 1 1979 RSA Krugerrand gold 0.5 1981 RSA Krugerrand gold 0.1 1986 PRC Panda silver 1 1986 USA Liberty dollar gold 0.25 1986 USA Liberty... (2 Replies)
Discussion started by: Ramesh M
2 Replies

6. Shell Programming and Scripting

Sum value in a row and print the max

I have the input file in attached. I want the output file : Date , Time , Max_Bearer 11/01/2013 , 23:00 , 1447.894167 11/02/2013 , 00:00 , 1429.266667 11/03/2013 , 00:00 , 712.3175 11/04/2013 , 22:00 , 650.9533333 11/05/2013 , 23:00 , 665.9558333 11/06/2013 , 23:00 , 659.8616667... (2 Replies)
Discussion started by: justbow
2 Replies

7. Shell Programming and Scripting

How to get the sum?

hi Gurus, I have an extract as seen below: INPUT 2015-08-24 15:00:00.0 |TCSERVER01 |ServiceEventHandler |2283 2015-08-24 15:01:00.0 |TCSERVER01 |ServiceEventHandler |576 2015-08-24 15:02:00.0 |TCSERVER01 |ServiceEventHandler |833 2015-08-24 15:03:00.0 |TCSERVER01 |ServiceEventHandler... (6 Replies)
Discussion started by: reignangel2003
6 Replies

8. Shell Programming and Scripting

awk sum of all columns needs to print exact amount

Hi I have attached txt file as input, and i'm able to calculate sum of columns at the end but the format of sum is not coming up right. awk -F"," '{for (i=4;i<=NF;i++) sum+=$i}{print}; END { sum="Total:"; for (i=1;i<=NF;i++) {printf sum ","} print "\n"}' input.txt check the o/p file, at... (6 Replies)
Discussion started by: manas_ranjan
6 Replies

9. Shell Programming and Scripting

awk - Print Sum

Hi, I have an awk command that I am using, and part of it sums COL_9 however when I read the output it is not including decimal places; awk ' BEGIN{FS=OFS=","} NR==1{print;next} {a+=$9 c = $12 d = $18 } END{for(i in a) {split(i,b,";"); print $1, $2, $3, b, $5, $6, b, b, a, $10, $11,... (1 Reply)
Discussion started by: Ads89
1 Replies
AMC-ANNOTE(1)						       Auto Multiple Choice						     AMC-ANNOTE(1)

NAME
AMC-annote - completed answer sheets annotation after marking for AMC multiple choice exams. SYNOPSIS
auto-multiple-choice annote --projet project-dir --data project-data-dir --fich-assoc assoc.xml [annotation options...] DESCRIPTION
The AMC-annote.pl command annotates papers scans with scores for all questions, global score and mark, resulting in JPEG files (one for each page). --projet project-dir sets the project directory. --data project-data-dir gives the directory where data files are (see for example AMC-prepare(1)). --cr project-cr-dir sets the project reports directory, where to find data capture reports prepared by AMC-analyse(1), and where to output annotated scans. Default value is project-dir/cr. --fich-noms students-list.csv sets the students list file name. --noms-encodage encoding selects an encoding for file students-list.csv (default is utf-8). --qualite qual sets JPEG quality for output files. Default value is 65. --taille-max maxsize sets the maximal size for output files (in the format widthxheight, in pixels). Default value is 1000x1500. --pointsize-nl lines sets the size of texts requiring that with this size, the number of text lines that fits on the page height must be lines. Default value is 60. --verdict header sets the text header to be printed on each first page of the students copies. This text may contain CR characters for multi-line headers. Some sequences are substituted in it: %S is replaced by the student total score. %M is replaced by the maximum total score. %s is replaced by the student mark. %m is replaced by the maximum mark. %(ID) is replaced by the student's name. %(COL) is replaced by the value of column COL in the students list for the curent student. --ch-sign nc Sets the number nc of significant digits to use when printing global mark. --symbols symbols-definition defines how boxes will be annotated. symbols-definition is a comma separated list of H-A:shape:colour constructs, where H is 0 or 1 depending on wether the box has to be checked or not, A is 0 or 1 depending on wether the box is actually checked or not, shape is one of none, circle, mark, box and coulour is a colour (name or #RGB, see ImageMagick or GraphicsMagick documentation for details). Default value is "0-0:none,0-1:circle:red,1-0:mark:red,1-1:mark:blue". --position pos sets the position of individual questions scores. pos may be 'none' (do dot write individual scores), 'marge' (write scores in the margin) or 'case' (write scores at the left of the left-most box for the question. --ecart dx sets the horizontal space to let between individual question score and the leftmost box when --position case is used. --ecart-marge x sets the x position for individual questions scores when written in the margin (in em units). --line-width lw sets the line width for symbols drwan on the scans (in pixels). Default value is 2. --indicatives bool say if indicative questions are to be annotated (use 1 for a true value; default is false). --debug file.log gives a file to fill with debugging information. AUTHORS
Alexis Bienvenue <paamc@passoire.fr> Main author Jean Berard Translation from French Georges Khaznadar Translation from French COPYRIGHT
Copyright (C) 2008-2012 Alexis Bienvenue This document can be used according to the terms of the GNU General Public License, version 2 or later. Auto Multiple Choice 1.1.1 06/19/2012 AMC-ANNOTE(1)
All times are GMT -4. The time now is 05:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy