LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-13-2017, 08:39 AM   #1
Pheonix777
LQ Newbie
 
Registered: Nov 2017
Posts: 7

Rep: Reputation: Disabled
Unhappy Bash scripting to list normal users without using awk.


How do i change this command to a script?this script is to list the normal users in bash?

$ cut -d: -f1-3 /etc/passwd | grep [1-6][0-9][0-9][0-9] | cut -f1 -d:
 
Old 11-13-2017, 09:03 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,940

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211
Same way you'd turn any command into a script.

If you don't know how to do that then take a look at http://tldp.org/LDP/abs/html/index.html
 
1 members found this post helpful.
Old 11-13-2017, 10:13 AM   #3
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,171
Blog Entries: 3

Rep: Reputation: 2064Reputation: 2064Reputation: 2064Reputation: 2064Reputation: 2064Reputation: 2064Reputation: 2064Reputation: 2064Reputation: 2064Reputation: 2064Reputation: 2064
The ABS, mentioned above, is a good start. At the same time I'd recommend also looking at the following:

Also, sed can rather closely replace the script you have shown:

Code:
sed -r '/^[^:]*:[^:]*:[1-9][0-9]{3}/!d; s/:.*//; /^nobody$/d;' /etc/passwd
However, the task you describe is quite suited to AWK:

Code:
awk '$3>1000 && $1!="nobody" { print $1 }' FS=':' /etc/passwd
Some distros might start the normal users at a lower UID than 1000.

Last edited by Turbocapitalist; 11-13-2017 at 10:15 AM.
 
1 members found this post helpful.
Old 11-13-2017, 11:04 AM   #4
Pheonix777
LQ Newbie
 
Registered: Nov 2017
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thank u guys
 
Old 11-13-2017, 12:24 PM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,199

Rep: Reputation: 547Reputation: 547Reputation: 547Reputation: 547Reputation: 547Reputation: 547
With shell built-ins
Code:
while IFS=: read user x uid gid gcos dir shell; do [ $uid -ge 1000 ] && echo "$user"; done < /etc/passwd
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] awk, bash scripting increase efficiency ip_address Programming 33 08-19-2012 11:17 AM
Scripting using a Mix of Bash, Awk, and Sed rafir Programming 5 10-12-2011 01:59 PM
Bash scripting, deleting an entry from a list Dee-ehn Linux - Software 2 04-06-2007 06:15 AM
Bash scripting problem: Can't get a list of all files, including hidden ones oxi Programming 24 03-12-2007 06:19 AM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration