AWK-COUNT


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers AWK-COUNT
# 1  
Old 08-09-2010
AWK-COUNT

Hi ,

HOW DO I COUNT THE NO of fields in a particular line of a file using awk

EX:

If file name is Pravee

a|2|3|4|y
the command shid display the result as 4

Please advise
# 2  
Old 08-09-2010
Code:
awk -F'|' '{print NF}' file_name

NF stands for number of fields

Last edited by Franklin52; 08-09-2010 at 03:28 AM.. Reason: Please use code tags, thank you!
# 3  
Old 08-09-2010
Many Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Category and count with awk

I want to categorize and count the as below: Input file: A1 G1 C1 F1 A2 G1 C1 F1 A3 G1 C1 F2 A4 G1 C2 F2 A7 G1 C2 F2 A8 G1 C2 F3 A11 G1 C2 F3 A23 G1 C2 F3 B4 G1 C2 F3 AC4 G2 C3 F4 B6 G2 C4 F4 BB5 G2 C4 F4 A25 G2 C5 F4 B13 G2 C5 F5 D12 G2 C5 F5 D2 G2 C5 F5 (3 Replies)
Discussion started by: aydj
3 Replies

2. Shell Programming and Scripting

awk to count using each unique value

Im looking for an awk script that will take the unique values in column 5, then print and count the unique values in column 6. CA001011500 11111 11111 -9999 201301 AAA CA001012040 11111 11111 -9999 201301 AAA CA001012573 11111 11111 -9999 201301 BBB CA001012710 11111 11111 -9999 201301... (4 Replies)
Discussion started by: ncwxpanther
4 Replies

3. Shell Programming and Scripting

How to count a number using awk?

hi, does any one know how to compare a file1 with many files and have to count a number (i.e. 1) like the following ..Thanx in advance input file1 file2 file3 filen 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 output instances in file1 only - 2 instances in... (3 Replies)
Discussion started by: quincyjones
3 Replies

4. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 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

awk and count sum ?

I have a input.txt file which have 3 fields separate by a comma place, os and timediff in seconds tampa,win7, 2575 tampa,win7, 157619 tampa,win7, 3352 dallas,vista,604799 greenbay,winxp, 14400 greenbay,win7 , 518400 san jose,winxp, 228121 san jose,winxp, 70853 san jose,winxp, 193514... (5 Replies)
Discussion started by: sabercats
5 Replies

7. Shell Programming and Scripting

count and awk

Hi my task is to show the percentage of files accessed in /home in one week. I have got as far as displying the files, kind of. I am not sure how to format them into a list. I've tried using awk but hasn't worked yet. any help would be fantastic. this is what i have got so far echo "The... (4 Replies)
Discussion started by: AngelFlesh
4 Replies

8. Shell Programming and Scripting

Sort and count using AWK

Hi, I've a fixed width file where I need to count the number of patterns from each line between characters 1 to 15 . so can we sort them and get a count for each pattern on the file between 1 to 15 characters. 65795648617522383763831552 410828003265795648 6175223837... (5 Replies)
Discussion started by: rudoraj
5 Replies

9. Shell Programming and Scripting

count the max by awk

hey everybody .. I have a problem when I use this command to count the Max number by awk it give to me 99 while there are numbers bigger than 99 awk 'NR==0 { temp = $0 ;next} { if ( $0 >= temp ) { temp=$0 } } END{ print "Maximum Number:"temp""}' file thank you for your help... (9 Replies)
Discussion started by: halola85
9 Replies

10. Shell Programming and Scripting

to count their numbers using awk

suppose u have a file AAG AAG GYG HYH GTG AAG AAG HYH GYG HUH JUJ JUJ AAG so output shud have AAG = 5 GYG=2 HYH=2 HUH=1JUJ=2 (3 Replies)
Discussion started by: cdfd123
3 Replies
Login or Register to Ask a Question