Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I remember feeling that way, too. Here, this is a /little/ clearer, with extended regex:
Code:
sed -r 's/(wheel:.*)/\1,user3/' /etc/group
Regex is a powerful tool - it's a trade off between ease of use and capability of expression. I think if we tried to create such a regular expression language of our own it might end up being just as ugly, if only different.
Incidentally, if I am correctly guessing what you're trying to do, you might find it easier to just add the group membership to the user's list with this command:
It's not really cryptic, its just a language you don't understand (yet). Basically as said above the language you do not understand is regular expressions... (also the shell escapes get confusing but come second nature when you realize they are shell escapes) Here is a good getting started tutorial: http://gnosis.cx/publish/programming...pressions.html
You don't have to get too advanced to get a good grasp and be able to start using them, also regular expressions are supported in many languages and commands so knowing a little bit comes in handy.
Quote:
Originally Posted by Dark_Helmet
And a slight modification to jschiwal's pattern
Code:
/^wheel:/s/\(.*\)/\1,user3/
EDIT:
Just to clarify, this form and jhwilliams's are the same thing--just formatted differently (as far as I can tell)
the above sed line will not work correctly if there is no user in the wheel group... (the sed line will work. the group entry will not.)
This should work though...
Code:
sed "/^wheel:/s/\(.*\)/\1,user3/;s/:,/:/" /etc/group
Incidentally, if I am correctly guessing what you're trying to do, you might find it easier to just add the group membership to the user's list with this command:
Code:
sudo usermod -a -G wheel user3
Excellent! I wonder why I never thought about adding users to the wheel group this way.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.