counting particular record format in a file using AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting counting particular record format in a file using AWK
# 1  
Old 02-02-2012
Question counting particular record format in a file using AWK

I am trying to count records of particular format from a file and assign it to a variable. I tried below command

Code:
 
br_count=wc -l "inputfile.dat"| awk -F"|" '{if (NF != "14") print }'

but I amnot able to get it done. Please share me some idea how to get it done.

Thanks in advance
# 2  
Old 02-02-2012
Try this:
Code:
grep -v "14$" inputfile.dat | wc -l

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-02-2012
Code:
count=$( grep -cv "14" infile )

--ahamed
# 4  
Old 02-02-2012
Thanks balajesuri...
But I want that count to be assigned to a variable.
Please show me how to do show....

---------- Post updated at 10:57 PM ---------- Previous update was at 10:53 PM ----------

Quote:
Originally Posted by ahamed101
Code:
count=$( grep -cv "14" infile )

--ahamed
Thanks Ahamed...
I tested the above command. It given a count as 3, but the source file had 4 actually... Smilie
# 5  
Old 02-02-2012
Paste your inputfile...

--ahamed
# 6  
Old 02-03-2012
I am trying to count the records in a file having '|' in it.
The source file will look as below

Quote:
Date: 12-08-1987
created by: fahim
D|373652879|34511433|0|0|0|0|0|40853|1336|e48999|OR|Save Original| Line|
Date: 12-08-1990
created by: raja
D|373652881|2698|0|0|0|0|0|40853|1336|e48999|OR|Save Original Line||
Date: 12-08-1993
created by: zabeen
D|373652883|9589|0|0|0|0|0|40853|1336|e48999|OR|Save| Original| Line|
Date: 12-08-1996
created by: Abhishek
D|373652885|3427|0|0|0|0|0|40853|1336|e48999|OR||Save| Original Line|
Expected output : 4

Sorry for not conveying the requirement properly before Smilie
# 7  
Old 02-03-2012
Code:
grep -c '|' file

Guru.
This User Gave Thanks to guruprasadpr For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Counting lines in a file using awk

I want to count lines of a file using AWK (only) and not in the END part like this awk 'END{print FNR}' because I want to use it. Does anyone know of a way? Thanks a lot. (7 Replies)
Discussion started by: guitarist684
7 Replies

2. Shell Programming and Scripting

Counting elements in each record

Hello, I have a file such as below: 0 0 . . 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 1I want to count the number of 0 and 1 in each line (. represents no data) and print them into two columns, that is:... (3 Replies)
Discussion started by: Homa
3 Replies

3. Shell Programming and Scripting

Shell script with awk command for counting in a file

Hi, I hope you can help me with the awk command in shell scripting. I want to do the following, but it doesn't work. for i in $REF1 $REF2 $REF3; do awk '{if($n>=0 && $n<=50000){count+=1}} END{print count}' ${DIR}${i} >${DIR}${i}_count.txt done REF1 to REF3 are only variables for .txt... (1 Reply)
Discussion started by: y.g.
1 Replies

4. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

5. Shell Programming and Scripting

awk-filter record by another file

I have file1 3049 3138 4672 22631 45324 112382 121240 125470 130289 186128 193996 194002 202776 228002 253221 273523 284601 284605 641858 (8 Replies)
Discussion started by: biomed
8 Replies

6. Shell Programming and Scripting

[AWK script]Counting the character in record and print them in condition

.......... (1 Reply)
Discussion started by: Antonlee
1 Replies

7. UNIX for Dummies Questions & Answers

syntax for counting & printing record count

Hi I have a complex script which outputs a text file for loading into a db. I now need to enhance this script do that I can issue an ‘lp' command to show the count of the number of records in this file. Can anybody give me the necessary syntax ? (2 Replies)
Discussion started by: malts18
2 Replies

8. Shell Programming and Scripting

Counting duplicate entries in a file using awk

Hi, I have a very big (with around 1 million entries) txt file with IPv4 addresses in the standard format, i.e. a.b.c.d The file looks like 10.1.1.1 10.1.1.1 10.1.1.1 10.1.2.4 10.1.2.4 12.1.5.6 . . . . and so on.... There are duplicate/multiple entries for some IP... (3 Replies)
Discussion started by: sajal.bhatia
3 Replies

9. Shell Programming and Scripting

Counting multiple entries in a file using awk

Hi, I have a big file (~960MB) having epoch time values (~50 million entries) which looks like 897393601 897393601 897393601 897393601 897393602 897393602 897393602 897393602 897393602 897393603 897393603 897393603 897393603 and so on....each time stamp has more than one... (6 Replies)
Discussion started by: sajal.bhatia
6 Replies

10. Red Hat

Counting columns in a delimited record with NULLs

I am trying to count the number of columns in a delimited flat file. The record is tab delimited. When I use the command wc -w, I am getting unexpected results when the record contains a NULL value. I believe it is because there is a "word" missing. The below example will return 4 words... (2 Replies)
Discussion started by: nmalencia
2 Replies
Login or Register to Ask a Question