I want to display all users that its UID between 300 and 500. I tried the grep command but I can't get the result that I need.
I tried this syntax, but it does not work:
cat /etc/passwd | grep *:[300-500]
egrep 'x:3[0-9][0-9]:|x:4[0-9][0-9]:|x:500:' /etc/passwd
or more eloquent
egrep 'x:[3-4][0-9][0-9]:|x:500:' /etc/passwd
Using awk, here is your answer:
awk -F: '$3 < 500 && $3 > 300 { print $0 }' /etc/passwd
You can print $1 if you just want the username.
print $1
Copyright © 2021 Jogjafile Inc.
or more eloquent