Total of 5th column using awk or any other utility in UNIX??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Total of 5th column using awk or any other utility in UNIX??
# 1  
Old 02-06-2013
Total of 5th column using awk or any other utility in UNIX??

Hi I have this file which contains


Code:
Code:
Al,AADESH,id1_0,23,2013-01-28,2,2			
Al,AADESH,id1_0,23,2013-01-29,4,4			
Al,AADESH,id1_0,23,2013-01-30,2,1			
Al,AADESH,id1_0,31,2013-01-29,1,1			
Al,AESH,id1_0,31,2013-01-31,2,2			
Al,AESH,id2_2,23,2013-01-29,1,1			
Al,AESH,id2_2,31,2013-01-31,1,1			
Al,AESH,id2_3,31,2013-01-29,1,1


I want to find the sum of the 5th column...
# 2  
Old 02-06-2013
Quote:
Originally Posted by nikhil jain
Al,AADESH,id1_0,23,2013-01-28,2,2
Al,AADESH,id1_0,23,2013-01-29,4,4
I want to find the sum of the 5th column...
5th column is date! How do you want to sum the 5th column?
# 3  
Old 02-06-2013
sorry 6th column..... :-P i counted wrong...
# 4  
Old 02-06-2013
Code:
awk -F, '{ s+=$6 } END { print s }' file

This User Gave Thanks to Yoda For This Post:
# 5  
Old 02-11-2013
hey the same issue persists

how do i find the total of 6th and 7th column simultaneously??

Code:
Code:
awk -F, '{ total += $6 total1 += $7 }; END { print total total1 }'

is not working.............
# 6  
Old 02-11-2013
Put a semicolon between the two commands.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search spaces in 5th column in large file

i have a file having 5 columns with more than million records. And i want to search using UNIX command to find if there are any spaces in 5th column. any please help. (1 Reply)
Discussion started by: sivakumar.p
1 Replies

2. Shell Programming and Scripting

Calculate 5th percentile based on another column

I would like to have some help in calculating 5th percentile value of column 2 for each site, the input is like below:site val1 val2 002 10 25.3 002 20 25.3 002 30 25.3 002 40 20 002 50 20 002 60 20 002 70 20 002 80 30 002 90 30 002 100 30 002 120 30 003 20 30.3 003 20 30.3 003 30 20... (2 Replies)
Discussion started by: wuhuai
2 Replies

3. Shell Programming and Scripting

awk command to find total number of Special character in a column

How to find total number of special character in a column? I am using awk -f "," '$col_number "*$" {print $col_number}' file.csv|wc -l but its not giving correct output. It's giving output as 1 even though i give no special character? Please use code tags next time for your code and... (4 Replies)
Discussion started by: AjitKumar
4 Replies

4. Shell Programming and Scripting

Column total

Input `0B0A RDF1+TDEV 45 BL_lmapm03 `0CE7 TDEV 59 BL_lmapm03 `0B09 RDF1+TDEV 70 BL_lmapm02 `0CE6 TDEV 59 BL_lmapm02 `0B08 RDF1+TDEV 70 BL_lmapm01 `0CE5 TDEV 59 BL_lmapm01 Output... (2 Replies)
Discussion started by: greycells
2 Replies

5. Linux

Filter a .CSV file based on the 5th column values

I have a .CSV file with the below format: "column 1","column 2","column 3","column 4","column 5","column 6","column 7","column 8","column 9","column 10 "12310","42324564756","a simple string with a , comma","string with or, without commas","string 1","USD","12","70%","08/01/2013",""... (2 Replies)
Discussion started by: dhruuv369
2 Replies

6. Shell Programming and Scripting

Total of a column from a file

Hi i need to calculate the total of a column from a file in ksh vi file.txt System : CBSE ent=0.1 me=Cap Subject Maths Science xxxxx 56 98 yyyy 89 67 ooo 67 32 Here i need to calculate only the total of Maths column alone i.e., 56+89+67 ... (4 Replies)
Discussion started by: Priresh
4 Replies

7. 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

8. Shell Programming and Scripting

shell script to sort the 5th column

hi folks, I have this data in a data.txt file and i want to sort the 5th column and in descending order: Jun 15 119.167.247.40 = 23 Jun 15 119.167.247.40 = 3 Jun 15 208.115.46.125 = 12 Jun 15 208.115.46.125 = 6 Jun 15 210.51.10.160 = 20 I want this sample output: Jun... (2 Replies)
Discussion started by: linuxgeek
2 Replies

9. Shell Programming and Scripting

Finding the total of a column using awk

Here is my file name countries USSR 8650 262 Asia Canada 3852 24 North America China 3692 866 Asia USA 3615 219 North America Brazil 3286 116 South America India 1269 637 Asia Argentina 1072 ... (8 Replies)
Discussion started by: ironhead3fan
8 Replies

10. Shell Programming and Scripting

Can we use 'tr' command to print 5th column of output of 'ls -l'

Hi All, I know awk command can do it, but can we use tr command to print 5th column of out put 'ls -l' command???? Regards, Nidhi... (4 Replies)
Discussion started by: Nidhi2177
4 Replies
Login or Register to Ask a Question