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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GREP or WC?

Status
Not open for further replies.

jodders

Programmer
Nov 12, 2003
13
0
0
GB
I a little rusty on UNIX and was wondering if anyone can tell me the commands for this.

I have a database with group names,username and name

eg. B ID123 Jones/A
C iD122 SMilth/a
B id322 Hae/H

and want to just count the group names.

B 2

Cant seem to find how to do this.I have tried using

wc -l < .txt, but that only counts the lines,and not the group.
 
Use
Code:
grep -c 'B' file
to count the number of matches.

--
 
To test for 'B' in field 1 only :

grep -c '^B' file

Jean Pierre.
 
To count all the groups:[tt][ignore]
awk '
{++a[$1]}END{for(g in a)print g,a[g]}
' /path/to/inputfile[/ignore][/tt]

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top