Can I improve this AWK/SED script that lists all users in columns?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can I improve this AWK/SED script that lists all users in columns?
Hi there,
Building a user management script (add/delete/lock/unlock/list/etc users) and building my line to pull all usernames from /etc/passwd and display ONLY user names (no machine names, no special names) and I am pretty close. I'd like to improve it though.
Building a user management script (add/delete/lock/unlock/list/etc users) and building my line to pull all usernames from /etc/passwd and display ONLY user names (no machine names, no special names) and I am pretty close. I'd like to improve it though.
Why don't you use sort -u here? This isn't an issue given your input data, but sort | uniq -u will keep only lines that have no duplicates. You might also compare the login shells to /etc/shells rather than assuming regular users use bash.
Kevin Barry
Why don't you use sort -u here? This isn't an issue given your input data, but sort | uniq -u will keep only lines that have no duplicates. You might also compare the login shells to /etc/shells rather than assuming regular users use bash.
Kevin Barry
Will uniq -u ignore lines that have duplicates (that is, if a line has a duplicate, remove BOTH lines)? My intention is to list, with no duplications, every user on the system (minus machine names, which for us contain a "$" sign).
AFAIK all our users use Bash, but if it would help make the script more portable I can use /etc/shells instead.
Will uniq -u ignore lines that have duplicates (that is, if a line has a duplicate, remove BOTH lines)?
Yes, it will remove both lines. In other words, only lines occurring once (consecutively) will be printed. I think a duplicate username in /etc/passwd would be an error you'd want to see and fix rather than mask.
Quote:
Originally Posted by hgate73
AFAIK all our users use Bash, but if it would help make the script more portable I can use /etc/shells instead.
I'm not sure if all *nix systems use /etc/shells, but I would use it in case someone later on wants their shell set to something else.
Kevin Barry
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.