Specific values from a list, awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Specific values from a list, awk
# 1  
Old 08-21-2013
Specific values from a list, awk

Hello together!

I have a list like this
Code:
1 3
2 5
3 7
4 2

Now I want to take the average of the second column and multiply it by the difference of the first and last value of the first column.
I posted an similar thread, but now I wonder how I can tell awk in an easy way to take specific values (In this case the first and the last of the first column)

The awk script should do this mathematical :
Code:
 print ( (3+5+7+2)* (4 - 1) )

Thanks a lot!

Björn
# 2  
Old 08-21-2013
formula in example does not show average calculation, but try:
Code:
awk 'NR==1 {a=$1} {b+=$2; c=$1} END {print (b/NR) * (c - a)}' input

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 08-22-2013
Thank you rdrtx1!
That is was what im searchin for.
You were right I lost the denominator.
The (c - a) term is a significance.Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to match file1 and extract specific tag values

File2 is tab-delimeted and I am trying to use $2 in file1 (space delimeted) as a search term in file2. If it is found then the AF= in and the FDP= values from file2 are extracted and printed next to the file1 line. I commented the awk before I added the lines in bold the current output resulted. I... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

Find specific pattern and change some of block values using awk

Hi, Could you please help me finding a way to replace a specific value in a text block when matching a key pattern ? I got the keys and the values from a command similar to: echo -e "key01 Nvalue01-1 Nvalue01-2 Nvalue01-3\nkey02 Nvalue02-1 Nvalue02-2 Nvalue02-3 \nkey03 Nvalue03-1... (2 Replies)
Discussion started by: alex2005
2 Replies

3. Shell Programming and Scripting

awk to remove mutiple values from specific pattern, leaving a single value

In the awk below I am trying to remove all instances after a ; (semi-colon) or , (comma) in the ANN= pattern. I am using gsub to substitute an empty string in these, so that ANN= is a single value (with only one value in it the one right after the ANN=). Thank you :). I have comented my awk and... (11 Replies)
Discussion started by: cmccabe
11 Replies

4. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

5. Shell Programming and Scripting

awk to store in a list the values of certain fileds

Dear Group, I have following input: sa;sb;sc;sd;period;ma;mb;mc;md;me sa1;sb1;sc1;sd1;200001;ma1;mb1;mc1;md1;me1 sa2;sb2;sc2;sd2;200002;ma2;mb2;mc2;md2;me2 sa3;sb3;sc3;sd3;200003;ma3;mb3;mc3;md3;me3 first line contains the headers! I want to create with one pass the following output:... (8 Replies)
Discussion started by: suturjik
8 Replies

6. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

7. Shell Programming and Scripting

iterate through list of numbers and print specific lines with awk

Could someone please point me in the right direction with the following? I have a program that generates logs that contains sections like this: IMAGE INPUT 81 0 0.995 2449470 0 1726 368 1 0.0635 0.3291 82 0 1.001 2448013 0 1666 365 1 0.0649 ... (4 Replies)
Discussion started by: euval
4 Replies

8. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies
Login or Register to Ask a Question