Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find record count of a particular value in a column in a text file 1

Status
Not open for further replies.

navink123

Programmer
Sep 2, 2003
21
US
I have a large data file. I need to find how many records in a particular column had a specific value.
e.g.
Its a third column in the file and the position of the column is 30 to 34. The values in the column is a combination of 1's and 0's like
10000
11010
11111
00000
01111

How can I find the record count of how many rows in this column has first character 1, how many have 2nd character 1 and so on till the end of column.

Thanks,
NK
 
Try something like this:
Code:
awk '
{for(i=0;i<=4;++i)c[i]+=substr($0,30+i,1)}
END{for(i=0;i<=4;++i)printf &quot;Col%d : %d\n&quot;,30+i,c[i]}
' /path/to/input

Hope This Help
PH.
 
How about

cut -c30-34 /path/to/input | sort | uniq -c

or

cut -c30-34 /path/to/input | awk '{a[$0]++}END{for(itm in a) print a[itm] &quot; &quot; itm}'



Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
uniq -c... how very useful. I had written my own script to do what it does, thanks!

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top