To get you started you can use awk
to search for lines in a file that contain a string like so:
$ awk '/CFS264/ { .... }' lastloggedin
The bits in the { .... }
will be the commands required to tally up the number of lines with that string. To confirm that the above is working you could use a print $0
in there to simply print those lines that contain the search string.
$ awk '/CFS264/ { print $0 }' lastloggedin
As to the counting, if you search for "awk counter" you'll stumble upon this SO Q&A titled: using awk to count no of records. The method shown there would suffice for what you describe:
$ awk '/CFS264/ {count++} END{print count}' lastloggedin
Example
$ last > lastloggedin
$ awk '/slm/ {count++} END {print count}' lastloggedin
758
$ grep slm lastloggedin | wc -l
758
$ grep -c slm lastloggedin
758
NOTE: You don't say which field CFS264 pertains to in the last
output. Assuming it's a username then you could further restrict the awk
command to search only that field like so:
$ awk '$1=="CFS264" { print $0 }' lastloggedin
awk
? If not, you could just usegrep -c CFS264 lastloggedin | wc -l
.grep -c (something) (something) | wc -l
will always produce "1".