LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Extract range of users with awk (https://www.linuxquestions.org/questions/slackware-14/extract-range-of-users-with-awk-4175513061/)

kikinovak 08-02-2014 03:46 AM

Extract range of users with awk
 
Hi,

Here's a line using awk to extract "real" users on my system:

Code:

bash-4.2$ awk -F: '$3 > 999 {print $1}' /etc/passwd | sort
glagaffe
jktartempion
kikinovak
lgibaud
mshanseifan

Does anyone know how I can combine several conditions? I would like, for example, to extract only users with an UID between 1000 and 2000. In other words, $3 > 999 and $3 < 2000. I can't seem to find the correct syntax for that.

Cheers,

Niki

55020 08-02-2014 04:07 AM

awk -F: '$3 > 999 && $3 < 2000 {print $1}' /etc/passwd | sort

Protip: *Italian* coffee, not French ;)

kikinovak 08-02-2014 04:10 AM

Quote:

Originally Posted by 55020 (Post 5213627)
awk -F: '$3 > 999 && $3 < 2000 {print $1}' /etc/passwd | sort

Protip: *Italian* coffee, not French ;)

Thanks very much. I just found it out by myself. Just a matter of replacing & by &&. I really should wait until I wake up completely before undertaking this sort of task. Anyway, SOLVED.

kikinovak 08-02-2014 04:12 AM

Quote:

Originally Posted by 55020 (Post 5213627)
Protip: *Italian* coffee, not French ;)

San Marco coffee in a Riviera espresso machine, FYI.

:hattip:

55020 08-02-2014 04:15 AM

So that's why you woke up so quickly! :D


All times are GMT -5. The time now is 08:29 AM.