Awk to get all my regular users in shadow

I have a script.

I want to get all my regular users from /etc/shadow e.g all users which second term in shadow file begins with $ or !$.

My pattern is

sudo getent shadow | awk -F: '$2 ~ /^$/ || /^!$/ {print $1}'

It doesn't work for now.


Solution 1:

You need to escape the $, as it is a special char for "End of Line" much like ^ is "Beginning of Line".

sudo getent shadow | awk -F: '$2 ~ /^\$/ || $2 ~  /^!\$/ {print $1}'

Solution 2:

All users with a password set can be listed like this:

getent shadow | egrep '^[^:]*:[*!]:' -v | cut -f1 -d: