[tt]
I'm looking for an awk routine to mimic the uniq -c command for the following:
$ cat input
A
A
A
A
B
B
$ cat script
{ A[NR]=$0 }
END{
for(i=1;i<=NR;i++) {
if (A ~/A/)
a++
else if (A ~/B/)
b++
}
print "A:" a
print "B:" b
}
$ awk -f script input
A:4
B:2
Clearly the above works when specifying the strings to be counted in the file: "A" and "B".
How is it done without the string specification e.g. as with the case of counting the repeat occurance of, say, 100 strings in a file.
[/tt]
I'm looking for an awk routine to mimic the uniq -c command for the following:
$ cat input
A
A
A
A
B
B
$ cat script
{ A[NR]=$0 }
END{
for(i=1;i<=NR;i++) {
if (A ~/A/)
a++
else if (A ~/B/)
b++
}
print "A:" a
print "B:" b
}
$ awk -f script input
A:4
B:2
Clearly the above works when specifying the strings to be counted in the file: "A" and "B".
How is it done without the string specification e.g. as with the case of counting the repeat occurance of, say, 100 strings in a file.
[/tt]