How to do a count for the following?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to do a count for the following?
# 1  
Old 04-17-2012
How to do a count for the following?

Hi folks,

i've a excel record as follows, this one is just a small part of it:

Star_date Start_time End_date Duration(SSS.mmm)
Code:
20120417,230003.482,20120417,230003.881,000.399,6591198732     ,000001E0,002,02,002,149,00000000,525016100064010,6593340020     
20120417,230006.309,20120417,230006.461,000.152,6596818957     ,000001E1,001,02,002,121,00000000,525016180538090,85368989801    
20120417,230006.709,20120417,230006.881,000.172,6596780282     ,000001E2,001,02,002,121,00000000,525016112086974,8613440462     
20120417,230010.429,20120417,230010.711,000.282,6583874077     ,000001E3,001,02,002,123,00000000,525016165512281,6593340023     
20120417,230010.959,20120417,230011.142,000.183,6598337465     ,000001E4,001,02,002,121,00000000,525016180406916,8613441468     
20120417,230015.076,20120417,230015.392,000.316,6584013578     ,000001E5,005,02,002,130,00000000,525016131588748,6593340023     
20120417,230018.449,20120417,230018.622,000.173,6598166800     ,000001E6,001,02,002,121,00000000,525016112060464,66818110224    
20120417,230020.790,20120417,230020.962,000.172,6597330160     ,000001E7,001,02,002,121,00000000,525016180173156,6281107007     
20120417,230024.410,20120417,230024.581,000.171,6594650803     ,000001E8,001,02,002,131,00000000,525016166558076,947100140      
20120417,230031.499,20120417,230031.662,000.163,6583142875     ,000001E9,001,02,002,121,00000000,525016162290221,60120001451    
20120417,230037.309,20120417,230037.481,000.172,6593548012     ,000001EA,001,02,002,131,00000000,525016136580627,60192015765





My questions is how to compose a Unix command to count those columns which are having 121 records.
And this total numbers should be count by second(time).

I just drafted one as below:
Code:
zcat * | cut -c85-87 | awk '{if ($1=="121") print; }' | wc -l


This will count the columns between 85 to 87 which are having 121 records.
But it doesn't give me the total number of 121 records within one second.
Can anybody advise me?
Thanks Smilie
Moderator's Comments:
Mod Comment How to use code tags

Last edited by Scrutinizer; 04-17-2012 at 01:48 PM..
# 2  
Old 04-17-2012
What are you trying to count? I mean where in the excel file do you start - and - stop. what time period does that represent?
To me dividing the total by the time period in seconds should give you the result, no?
# 3  
Old 04-17-2012
I think attempt is to count number of occurrence of 121 in column 11 of file. If yes you could use this code
Code:
awk '{if($11==121) x+=1}END{print x}' FS=, infile


Last edited by 47shailesh; 04-20-2012 at 11:38 AM.. Reason: syntax correction
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies

2. Shell Programming and Scripting

Count the pipes "|" in line and delete line if count greter then number.

Hello, I have been working on Awk/sed one liner which counts the number of occurrences of '|' in pipe separated lines of file and delete the line from files if count exceeds "17". i.e need to get records having exact 17 pipe separated fields(no more or less) currently i have below : awk... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

4. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

5. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

6. Shell Programming and Scripting

Count the delimeter from a file and delete the row if delimeter count doesnt match.

I have a file containing about 5 million rows, in the file there are some records which has extra delimiter at random position. (we dont know the positions), now we have to Count the delimeter from each row and if the count of delimeter is not matching then I want to delete those rows from the... (5 Replies)
Discussion started by: Akumar1
5 Replies

7. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

8. Shell Programming and Scripting

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid... (4 Replies)
Discussion started by: singhabhijit
4 Replies

9. UNIX for Dummies Questions & Answers

Sorting using count, grep and count

Hi, I trying to sort information in a file by making count for every object. For example: A B A D A B C i would like to sort out count for each object (A's, B's and etc) but in actual case i dont know the object but i know the position ofthe object. do i need to use array as well? Any... (2 Replies)
Discussion started by: sukhpal_78
2 Replies

10. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies
Login or Register to Ask a Question