Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Calculate average from a given set of keys and values Post 303037867 by nans on Thursday 15th of August 2019 09:47:48 AM
Old 08-15-2019
Calculate average from a given set of keys and values

Hello,
I am writing a script which expects as its input a hash with student names as the keys and marks as the values. The script then returns array of average marks for student scored 60-70, 70-80, and over 90.


Output expected


Code:
50-70    1
70-90    3
over 90   0

The test script so far I have written looks like this


Code:
#!/bin/bash

ARRAY=( "ABC:60"
        "DEF:70"
        "GHI:75"
        "JKL:80" )

for student in "${ARRAY[@]}" ; do
    KEY="${student%%:*}"
    VALUE="${student##*:}"
    printf "%s's marks is %s.\n" "$KEY" "$VALUE"


done

I am able to store the input as hash with keys and its values but not able to calculate the average and give the output as expected. Any suggestions would be appreciated.


thank you

Last edited by nans; 08-15-2019 at 11:12 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

calculate average of column 2

Hi I have fakebook.csv as following: F1(current date) F2(popularity) F3(name of book) F4(release date of book) 2006-06-21,6860,"Harry Potter",2006-12-31 2006-06-22,,"Harry Potter",2006-12-31 2006-06-23,7120,"Harry Potter",2006-12-31 2006-06-24,,"Harry Potter",2006-12-31... (0 Replies)
Discussion started by: onthetopo
0 Replies

2. Programming

calculate average

I have a file which is 2 3 4 5 6 6 so i am writing program in C to calculate mean.. #include<stdio.h> #include<string.h> #include <math.h> double CALL mean(int n , double x) main (int argc, char **argv) { char Buf,SEQ; int i; double result = 0; FILE *fp; (3 Replies)
Discussion started by: cdfd123
3 Replies

3. Shell Programming and Scripting

Calculate average time using a script

Hello, I'm hoping to get some help on calculating an average time from a list of times (hour:minute:second). Here's what my list looks like right now, it will grow (I can get the full date or change the formatting of this as well): 07:55:31 09:42:00 08:09:02 09:15:23 09:27:45 09:49:26... (4 Replies)
Discussion started by: jaredhanks
4 Replies

4. Shell Programming and Scripting

AWK novice - calculate the average

Hi, I have the following data in a file for example: P1 XXXXXXX.1 YYYYYYY.1 ZZZ.1 P1 XXXXXXX.2 YYYYYYY.2 ZZZ.2 P1 XXXXXXX.3 YYYYYYY.3 ZZZ.3 P1 XXXXXXX.4 YYYYYYY.4 ZZZ.4 P1 XXXXXXX.5 YYYYYYY.5 ZZZ.5 P1 XXXXXXX.6 YYYYYYY.6 ZZZ.6 P1 XXXXXXX.7 YYYYYYY.7 ZZZ.7 P1 XXXXXXX.8 YYYYYYY.8 ZZZ.8 P2... (6 Replies)
Discussion started by: alex2005
6 Replies

5. Shell Programming and Scripting

Calculate Average AWK

I want to calculate the average line by line of some files with several lines on them, the files are identical, just want to average the 3rd columns of those files.:wall: Example file: File 1 001 0.046 0.667267 001 0.047 0.672028 001 0.048 0.656025 001 0.049 ... (2 Replies)
Discussion started by: AriasFco
2 Replies

6. UNIX for Dummies Questions & Answers

Average for multiple keys

Hi, I want to find row-wise average of multiple columns based on 2 columns. I have 30k values in the matrix with 94 cols. Example Input for cols 4 and 5 as keys 1 2 3 a 1 4 5 6 a 1 4 2 0 a 1 1 2 3 b 2 5 6 7 b 2 9 7 5 b 2 Output 3 3 3 a 1 5 5 5 b 2Here is what I have tried,... (5 Replies)
Discussion started by: ritakadm
5 Replies

7. Shell Programming and Scripting

Calculate average of top n% of values - UNIX

Hey guys, I have several huge tab delimited files which look like this: a 1 20 a 3 15 a 5 10 b 2 15 b 6 10 c 3 23 what I am interested is to calculate the average of top n% of data in third column. So for example for this file the top 50% values are: 23 20 (Please note that it... (11 Replies)
Discussion started by: @man
11 Replies

8. Shell Programming and Scripting

Calculate Average time of one column

Hello dears, I have a log file with records like below and want to get a average of one column based on the search of one specific keyword. 2015-02-07 08:15:28 10.102.51.100 10.112.55.101 "kevin.c" POST ... (2 Replies)
Discussion started by: Newman
2 Replies

9. Shell Programming and Scripting

Calculate average, azimut and distance

Gents, Please i will to get the distance and azimut from 2 coordinates: Usig excel formula i get the correct values, but i will like to do it using awk. Example A 35089.0 50345.016 9 75 1 2101774 77 70 79 483911.6 2380106.9 137.4 1 1 6 1 A 35089.0 50345.01620 75... (8 Replies)
Discussion started by: jiam912
8 Replies

10. Shell Programming and Scripting

Calculate the average per block.

My old school way is a one liner. And will search for average from SAR, to get the data receive rate. But, I dont think it is practical or accurate,. Because it calculates to off peak hours. I am planning to change it. My cron runs every 30 mins. When my cron runs, and my time is 14:47pm,, it will... (1 Reply)
Discussion started by: invinzin21
1 Replies
AMC-EXPORT(1)						       Auto Multiple Choice						     AMC-EXPORT(1)

NAME
AMC-export - exports marks for AMC multiple choice exams. SYNOPSIS
auto-multiple-choice export --data project-data-dir --module module --fich-noms students-list.csv [--noms-encodage list-encoding] --o output-file DESCRIPTION
The AMC-export.pl command exports marks from an Auto Multiple Choice exam. --data project-data-dir gives the directory where data files are (see for example AMC-prepare(1)). --module module selects a module for export. See below for the modules included in the AMC standard distribution. --fich-noms students-list.csv sets the students list file. --noms-encodage list-encoding selects an encoding for file students-list.csv (default is utf-8). --o output-file gives the output file name. --option-out options gives an option for selected module, in the form key=value (see below for possible options for each module). To specify multiple options, use --option several times. --sort sort-type sort the students names, depending on sort-type. If sort-type is l, use line number from students list file to sort. If sort-type is m, use mark (and name if marks are equal) to sort. If sort-type is i, use student number to sort. If sort-type is n, use name to sort (or line from students list if equal). --useall all if all is 0 or empty, only students with a scaned answer sheet appears in the output. If all is 1, all students in the students list appears in the output. MODULES
OpenDocument With "--module ods", an OpenDocument (for use by OpenOffice or LibreOffice for example) is produced. The following options are recognized: nom gives a name for the exam, to be written on the beginning of the sheet. code gives an short name for the exam, to be used as a tab name. columns sets the list of columns that are to be added to each student. Default value is student.key,student.name. stats with a true value, a table will be added with statistics for all questions. statsindic with a true value, a table will be added with statistics for all indicative questions. CSV With "--module CSV", a CSV file is produced. The following options are recognized: columns sets the list of columns that are to be added to each student. Default value is student.copy,student.key,student.name. decimal sets the decimal point (default is a dot). encodage sets the encoding to use for output (default is utf-8). separateur sets the character used between colums (default is a comma). entoure sets the character used to enclose strings (default is a double quote). ticked if not empty, additional columns (with "CHECKED:" prefix) are included to give all the checked boxes on all the sheets. This can be used by an external program to retrieve all the checked boxes when marks are not sufficient. Use value 01 to get 0;0;1;1;0 if boxes 3 and 4 are checked, and value AB to get CD if boxes 3 and 4 are checked. List With "--module List", a PDF file is produced with a list of marks for all students. The following options are recognized: pagesize The page size. Default value is a4. nom gives the name of the exam, to be printed at the top of the page. ncols The number of columns. Default value is 2. decimal sets the decimal point (default is a dot). 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-EXPORT(1)
All times are GMT -4. The time now is 05:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy