I'm looking for an easy, portable way to validate the number of fields in /etc/passwd, /etc/shadow, /etc/group and /etc/master.passwd. This would run on FreeBSD, Linux and other Un*xes. pwck does this, and more, but it only runs on Linux-based systems. How can I count the number of fields separated by colons in /etc/passwd?root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinFollowing the example in grep: count total number of occurrences, I came up with the following quick hack:cat /etc/passwd | while read LINE; do echo $LINE | grep -o ':'  |wc -l; doneBut I'm looking for a better way.
Verify that /etc/passwd has correct number of fields on each line?
text processing;users
awk -F: ' NF!=7 {print}' /etc/passwdshould do it.  If the number of fields is not 7, then print it out.