Find the Maximum value and average of a column

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Find the Maximum value and average of a column
# 1  
Old 01-30-2012
Find the Maximum value and average of a column

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
I am trying to complete a script which will allow me to find:
a) reads a value from the keyboard. (ask the user to provide a value)
b) reads each line from the "sercel_output2.3" file in a loop until it finds the value you are looking for
c) counts the occurrences of the value provided
Unitl here I can run the script but I am having trouble with the following two points. I can not use awk
d) fiind the maximum value in the column(there is only one column in the file)
e) calculate the average of the column. ( I only have one point after the decimal)



2. Relevant commands, code, scripts, algorithms:

can not use awk

3. The attempts at a solution (include all code and scripts):
Code:
echo "Please Provide a value"
 read x
 for value in $( cat sercel_output2.3 )
 do
    if  [ "$x" = "$value" ]
       then
          echo " value $x found "
       else
           echo " value $ x not found "
    fi
 done
 grep "$x" sercel_output2.3 | wc -l

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Southern Alberta Institue of Technology Calgary Alberta Canada
Patricia Casto Advanced Linux

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by DukeNuke2; 01-31-2012 at 03:52 AM..
# 2  
Old 01-30-2012
so, where you stuck ?
# 3  
Old 01-30-2012
we are stuck on how to write the codes for
d) fiind the maximum value in the column(there is only one column in the file)
e) calculate the average of the column. ( I only have one point after the decimal)

any suggestions would be a big help

Thank you
# 4  
Old 01-30-2012
Code:
 
max=0
for value in $( cat sercel_output2.3 )
do
 # check if $max is less than $value
 # if yes, then assign $max = $value
 # once this loop completed, $max will hold the maximum value
done
echo $max
 
sum=0
count=0
for value in $( cat sercel_output2.3 )
do
 # increment the count variable by 1 ( count = count + 1 )
 # sum = $sum + $value
done
# average  = $sum / $count

come with your own syntax, and let us know, if you need more help
# 5  
Old 01-30-2012
@dstewie: Did you try searching the forum for similar questions? https://www.unix.com/shell-programmin...ue-column.html

But I would encourage you to come up with your own logic and code it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to find maximum and minimum from column and store in other column

Need your support for below. Please help to get required output If column 5 is INV then only consider column1 and take out duplicates/identical rows/values from column1 and then put minimum value of column6 in column7 and put maximum value in column 8 and then need to do subtract values of... (7 Replies)
Discussion started by: as7951
7 Replies

2. Shell Programming and Scripting

Get maximum per column from CSV file, based on date column

Hello everyone, I am using ksh on Solaris 10 and I'm gathering data in a CSV file that looks like this: 20170628-23:25:01,1,0,0,1,1,1,1,55,55,1 20170628-23:30:01,1,0,0,1,1,1,1,56,56,1 20170628-23:35:00,1,0,0,1,1,2,1,57,57,2 20170628-23:40:00,1,0,0,1,1,1,1,58,58,2... (6 Replies)
Discussion started by: ejianu
6 Replies

3. Shell Programming and Scripting

Find minimum and maximum values based on column with associative array

Hello, I need to find out the minimum and maximum values based on specific column, and then print out the entire row with the max value. Infile.txt: scf6 290173 290416 . + X_047241 T_00113118-1 scf6 290491 290957 . + X_047241 T_00113118-2 scf6 290898 290957 . + X_047241 T_00113119-3 scf6... (2 Replies)
Discussion started by: yifangt
2 Replies

4. UNIX for Dummies Questions & Answers

Using awk to find and use the maximum value in column of data

Dear Unix Gurus, I have a text file with multiple columns, for example, see sample.txt below 0 1 301 1 4 250 2 6 140 3 2 610 7 1 180I want to find the maximum in, say, column 3, normalise all the values to this maximum value (to 4 decimal places) and spit everything into a new... (2 Replies)
Discussion started by: tintin72
2 Replies

5. Shell Programming and Scripting

Getting average ,maximum and minimum value

Hi Evreyone below is the sample data i have in one file Wed Jan 30 7 :04:50 2013 type1 419990050 101 ms Wed Jan 30 7 :04:58 2013 type1 488226363 101 ms Wed Jan 30 7 :05:03 2013 type1 431525334 101 ms Wed Jan 30 7 :05:48 2013 type2 400676615 101 ms Wed Jan 30 8 :09:46... (3 Replies)
Discussion started by: zozoo
3 Replies

6. Shell Programming and Scripting

Finding minimum maximum and average

I am trying to find the minimum maximum and average from one file which has values Received message from https://www.demandmatrix.net/app/dm/xml] in milliseconds. Received message from https://www.demandmatrix.net/app/dm/xml] in milliseconds. Received message from... (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

7. UNIX for Dummies Questions & Answers

Find the average based on similar names in the first column

I have a table, say this: name1 num1 num2 num3 num4 name2 num5 num6 num7 num8 name3 num1 num3 num4 num9 name2 num8 num9 num1 num2 name2 num4 num5 num6 num4 name4 num4 num5 num7 num8 name5 num1 num3 num9 num7 name5 num6 num8 num3 num4 I want a code that will sort my data according... (4 Replies)
Discussion started by: FelipeAd
4 Replies

8. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

9. Shell Programming and Scripting

Script to find the average of a given column and also for specified number of rows?

Hi Friends, In continuation to my earlier post https://www.unix.com/shell-programming-scripting/99166-script-find-average-given-column-also-specified-number-rows.html I am extending my problem as follows. Input: Column1 Column2 MAS 1 MAS 4 ... (2 Replies)
Discussion started by: ks_reddy
2 Replies

10. Shell Programming and Scripting

Script to find the average of a given column and also for specified number of rows??

Hi friends I have 100 files in my directory. Each file look like this.. Temp1 Temp2 Temp3 MAS 1 2 3 MAS 4 5 6 MAS 7 8 9 Delhi 10 11 12 Delhi 13 14 15 Delhi 16 17 ... (4 Replies)
Discussion started by: ks_reddy
4 Replies
Login or Register to Ask a Question