LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-02-2014, 03:46 AM   #1
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
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
 
Old 08-02-2014, 04:07 AM   #2
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

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

Protip: *Italian* coffee, not French
 
1 members found this post helpful.
Old 08-02-2014, 04:10 AM   #3
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Quote:
Originally Posted by 55020 View Post
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.
 
Old 08-02-2014, 04:12 AM   #4
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Quote:
Originally Posted by 55020 View Post
Protip: *Italian* coffee, not French
San Marco coffee in a Riviera espresso machine, FYI.

 
1 members found this post helpful.
Old 08-02-2014, 04:15 AM   #5
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
So that's why you woke up so quickly!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] extract lines using date range veda92 Programming 2 07-22-2013 05:58 AM
Command to extract a range of bytes from a file calande Linux - General 2 10-02-2011 11:58 AM
[SOLVED] Not able to extract last column from awk vinaytp Linux - Newbie 4 05-20-2011 04:27 AM
Awk - Extract a particular string thomchad Programming 17 04-04-2010 02:55 AM
Getting awk to extract scripts from a file jspaceman Programming 5 11-24-2002 06:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration