Counting records with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting records with AWK
# 1  
Old 01-20-2009
Counting records with AWK

I've been working with an awk script and I'm wondeing id it's possible to count records in a file which DO NOT contain, in this instance fields 12 and 13.

With the one script I am wanting to display the count for the records WITH fields 12 and 13 and a seperate count of records WITHOUT fields 12 and 13.

Here's my script:

BEGIN {
print
print "User Process ID Time Active"
print
}
$4 $6 $7 $8 $9 $10 $11 {
cmbaselicences ++
}
$12 $13 {
changebaselicences ++
}
{
print $4, $6, $7, $8, $9, $10, $11, $12, $13
}
END {
printf "\n\nUsers of SYNERGY-CMBase: (Total of 12 licenses issued; Total of %-2d", cmbaselicences
print " licences in use)"
printf "\n\nUsers of SYNERGY-ChangeBase: (Total of 11 licenses issued; Total of %-2d", changebaselicences
print " licences in use)\n"
print
}


and the file with the records..:

ccm_root phys-agsdev /dev/tty ChangeAdmin (v1.0) (Phys-agsdev/19353 201), start Tue 1/20 6:30 (linger: 1800)
ccm_root phys-agsdev /dev/pts/58 u414020 (v1.0) (Phys-agsdev/19353 745), start Tue 1/20 18:43


Fields 12 and 13 contain the "(linger: 1800)" entry.

Cheers
# 2  
Old 01-20-2009
Replace this:

Code:
$4 $6 $7 $8 $9 $10 $11 {
cmbaselicences ++
}
$12 $13 {
changebaselicences ++
}

with:

Code:
NF==11{cmbaselicences++}
NF==13{changebaselicences++}

Regards
# 3  
Old 01-20-2009
Code:
awk'
NF > 11 { ++changebaselicences }
NF < 12{ ++cmbaselicences }
END { ..... }
'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk counting question

Probably a simple to this, but unsure how to do it. I would prefer an AWK solution. Below is the data set. 1 2 3 2 5 7 4 6 9 1 5 4 8 5 7 1 1 10 15 3 12 3 7 9 9 8 10 4 5 2 9 1 10 4 7 9 7 12 6 9 13 8 For the second... (11 Replies)
Discussion started by: mollydog11
11 Replies

2. Shell Programming and Scripting

Counting the records based on condition

Hi Unix team, I have a file with 30 columns with tab delimited. I need to count the records based on column 18 & 21 data. So I cut the data from the file using awk -F"\t" '{print $18,$21}' foo.txt Following is the output: USED SEDAN USED SUV NEW SUV USED Truck USED Truck USED... (6 Replies)
Discussion started by: karumudi7
6 Replies

3. Shell Programming and Scripting

Counting Fields with awk

ok, so a user can specify options as is shown below: ExA: cpu.pl!23!25!-allow or ExB: cpu.pl!23!25!-block!all options are delimited by the exclamation mark. now, in example A, there are 4 options provided by the user. in example B, there are 5 options provided by the user. ... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

Counting number of records with string row delimiter

HI, i have a file like this t.txt f1|_f2|_ f1|_f2|_ f1|_f2|_ as if col delimiter is |_ and row delimiter |_\n trying to count number of records using awk $ awk 'BEGIN{FS="|_" ; RS="~~\n"} {n++}END{print n} ' t.txt 7 wondering how can i count this to 3 ? thx (9 Replies)
Discussion started by: aksforum
9 Replies

5. Shell Programming and Scripting

counting using awk

Hi, I want to perform a task using shell script. I am new to awk programming and any help would be greatly appreciated. I have the following 3 files (for example) file1: Name count Symbol chr1_1_50 10 XXXX chr3_101_150 30 YYYY File2: Name ... (13 Replies)
Discussion started by: Diya123
13 Replies

6. Shell Programming and Scripting

Averaging all fields while counting repeated records

Hi every one; I have a 31500-line text file upon which two following tasks are to be performed: 1: Rearranging the file 2: Taking the average of each column (considering number of zeros) and output the result into a new file This is the code I've come up with: awk '(NR%3150<3150)... (0 Replies)
Discussion started by: nxp
0 Replies

7. Shell Programming and Scripting

Help me in counting records from file

Hi, Please help me in counting the below records(1st field) from samplefile: Expected output: Count Descr ------------------------------------------- 7 Mean manager 14 ... (7 Replies)
Discussion started by: prashant43
7 Replies

8. Shell Programming and Scripting

counting non integer number in awk

Hi, I am having the following number in the file tmp 31013.004 20675.336 43318.190 30512.926 48992.559 277893.111 41831.330 8749.113 415980.576 28273.054 I want to add these numbers, I am using following script awk 'END{print s}{s += $1}' tmp its giving answer 947239 which is correct,... (3 Replies)
Discussion started by: chaitubek
3 Replies

9. Shell Programming and Scripting

Counting with Awk

I need "awk solution" for simple counting! File looks like: STUDENT GRADE student1 A student2 A student3 B student4 A student5 B Desired Output: GRADE No.of Students A 3 B 2 Thanks for awking! (4 Replies)
Discussion started by: saint2006
4 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question