Calculating number of records by field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculating number of records by field
# 1  
Old 07-07-2010
Calculating number of records by field

Hi,

I have CSV file which looks like below, i want to calulate number of records for each brand say SOLO_UNBEATABLE E and SOLO_UNBEATABLE F combined and record count is say 20 . i want to calculate for each brand, and here only first record will have all data and rest of record for the brand is with only two fields displayed.
Let me know how i can number of records for such situation ?

Code:
SOLO_UNBEATABLE	E	7	5/1/2010 13:00	5/6/2010 18:00	12:30	17:00	2263881188	Y	41216		Free Solo msg: Your monthly charge is past due. Top up now to reinstate your plan & avoid pay per use charges. Visit solomobile.ca/top-up. 						Sorry	 this address cannot receive incoming messages. Thank you for choosing Solo. To contact us	 visit solomobile.ca/contact-us	
							2263881964	Y												
							2263884224	Y												
							2263884246	Y
SOLO_UNBEATABLE	F	7	5/1/2010 13:00	5/6/2010 18:00	12:30	17:00	4162005872	Y	41216		Mess grat de Solo: Frais mensuels échus. Réapprovisionnez votre compte & éviter de payer à l'util. Détails: solomobile.ca/reapprovisionner. 						Désolé. Cette adresse ne peut recevoir de messages. Merci d'avoir choisi Solo. Visitez solomobile.ca/contactez-nous
							4183329551	Y									
							4184807455	Y									
							4185169291	Y									
							4185701898	Y									
							4185717607	Y									
Bell_BB	E	7	5/1/2010 13:00	5/6/2010 18:00	12:30	17:00	2506503556	Y	41216		Free Bell Msg: Your monthly payment is past due. Top up to reinstate your BlackBerry feature (may take 24 hrs). Visit bell.ca/topup						Sorry	 this address cannot receive incoming messages. Thank you for choosing Solo. To contact us	 visit solomobile.ca/contact-us
							2509368323	Y											
							2509475405	Y											
							2892609313	Y											
							2893562015	Y											
							4034781779	Y											
							4038210219	Y											
							5196517632	Y											
							6047039761	Y											
							6133189211	Y											
							6134309448	Y											
							9022473696	Y											
							9053517625	Y											
							9059121573	Y											
Bell_BB	F	7	5/1/2010 13:00	5/6/2010 18:00	12:30	17:00	5147182000	Y	41216		Mess grat Bell : Paiement mensuel en retard. Réapp. à bell.ca/reapprovisionnement pour rétablir votre option BlackBerry (peut prendre 24 h). 						Désolé. Cette adresse ne peut recevoir de messages. Merci d'avoir choisi Solo. Visitez solomobile.ca/contactez-nous		
Bell_MONTHLY	E	7	5/1/2010 13:00	5/6/2010 18:00	12:30	17:00	2263883220	Y	41216		Free Bell msg: Your monthly charge is past due. Top up now to reinstate your plan & avoid pay per use charges. Visit bell.ca/topup. 						Sorry	 this address cannot receive incoming messages. Thank you for choosing Solo. To contact us	 visit solomobile.ca/contact-us
							2267475054	Y											
							2267477589	Y											
							2267484229	Y											
							2267488725	Y											
							2267489010	Y											
							2267493332	Y											
Bell_MONTHLY	F	7	5/1/2010 13:00	5/6/2010 18:00	12:30	17:00	4183343530	Y	41216		Mess grat de Bell: Frais mensuels échus. Réapprovisionnez votre compte & éviter de payer à l'util. Détails: bell.ca/reapprovisionnement						Désolé. Cette adresse ne peut recevoir de messages. Merci d'avoir choisi Solo. Visitez solomobile.ca/contactez-nous
							4187142083	Y									
							4188127848	Y									
							4189051790	Y									
							4189529341	Y									
							4189575309	Y									
							4189604983	Y									
							4505613682	Y									
							4505664580	Y

# 2  
Old 07-07-2010
Give your expect output. Otherwise difficult to understand your request.

For example, how can you get the record count of 20 for SOLO_UNBEATABLE E and SOLO_UNBEATABLE F
# 3  
Old 07-08-2010
I got solution to requirement

Code:
BEGIN {FS=",";count=0;}

{
if ( NR == 1 )
   { next;
   }

if ($1 != "" )
    {
    if(NR != 2 ) { print prev_serv_list,count; }
    prev_serv_list=$1;
    count=0 ;

    }
    count++
}

END {
print prev_serv_list,count;
}


Last edited by Franklin52; 07-08-2010 at 09:14 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Calculating number of CPUs in Solaris-8

Hello, I have few old V210/V240, running Solaris-8. I am trying to find, number of physical CPUs, number of cores and number of virtual processors. psrinfo is giving me confusing status. It looks like, there are 2 physical CPUs, but psrinfo -p shows me just 1 bash-2.03$ psrinfo -v Status of... (4 Replies)
Discussion started by: ron323232
4 Replies

2. Shell Programming and Scripting

Performance of calculating total number of matching records in multiple files

Hello Friends, I've been trying to calculate total number of a certain match in multiple data records files (DRs). Let say I have a daily created folders for each day since the beginning of july like the following drwxrwxrwx 2 mmsuper med 65536 Jul 1 23:59 20150701 drwxrwxrwx 2 mmsuper... (1 Reply)
Discussion started by: EAGL€
1 Replies

3. Shell Programming and Scripting

Trouble calculating difference in number of days

Hi all, I have a requirement to calculate the difference of number of days of time stamp of a file and system date and if the difference is greater than 15 days it should prompt as previous month file otherwise current month file. Below is the code i used and it is working fine till now. (You... (2 Replies)
Discussion started by: Ravindra Swan
2 Replies

4. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

5. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

6. Shell Programming and Scripting

Counting non empty fields and calculating with that number

Hello all, I have a problem with a skript of mine: My input has the following format 1,33296 transcript_id"ENSRNOT00000018629" 0 1,33296 0 0 transcript_id"ENSRNOT00000029014" 0 0,907392 transcript_id"ENSRNOT00000016905" 0,907392 0 transcript_id"ENSRNOT00000053370" 0 0... (0 Replies)
Discussion started by: DerSeb
0 Replies

7. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

8. UNIX for Dummies Questions & Answers

Calculating the Number of Rows and Average

Hi All I like to know how can we calculate the number of rows and the average of the values present in the file. I will not know what will be the rowcount, which will be dynamic in nature of the file. eg. 29 33 48 30 28 (6 Replies)
Discussion started by: pk_eee
6 Replies

9. Shell Programming and Scripting

calculating a number

Hello all :) I need some help; I'm running the sp_spaceused command on various tables and saving the output to a file. So, I have an input file that has 3 rows - each row has 7 columns. I would like to 1) sort the file on the 4th column, 2) take the 4th column in the first row and add 25% to... (2 Replies)
Discussion started by: stonemonolith
2 Replies

10. UNIX for Dummies Questions & Answers

Calculating field using AWK, or GAWK script

Hello all, I'm totally new to UNIX/Linux but I'm taking a course in it at my local JC. My question: I have been tasked with writing a gawk script that will create a nicely formatted report. That part I've done ok on...however, the very last thing that must be done is a calculation of a... (4 Replies)
Discussion started by: Trellot
4 Replies
Login or Register to Ask a Question