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.
Hi guys, I'm trying to find exact matches of some users in the /etc/passwd file using "grep -w", but it doesn't always work.
For example, I have the following users:
I tried: grep -w "^john.stewart:" /etc/passwd to match all lines starting with john.stewart followed by colon... I have no idea why, but it doesn't work... it doesn't find anything, although it should. Any suggestions?
Oh, very helpful! Gee, now why didn't I think of that? Oh, wait, as a matter of fact, that's the first thing I did, but it doesn't seem like it helped, does it? You know, since I'm on this FORUM asking for HELP!
Listen, syg00, some people, like you, don't seem to grasp the meaning of the word FORUM. Let me explain, it's easy: If one can and WANTS to help, he can altruistically do so, if not, it's not a problem, nobody is pointing a gun at anybody ! But repeating phrases such as "Read the manual", "Use Google" is just redundant and the only thing you accomplish is increase the number of "no-substance-just-trying-to-be-arrogant" posts.
Wow, I can't believe that was the problem. You're absolutelly right! It works perfectly without "-w". I was using it because I thought it helped to match the exact string... guess that in my case it was doing the exact opposite... i'm not quite sure why.
Oh, very helpful! Gee, now why didn't I think of that? Oh, wait, as a matter of fact, that's the first thing I did, but it doesn't seem like it helped, does it? You know, since I'm on this FORUM asking for HELP!
Listen, syg00, some people, like you, don't seem to grasp the meaning of the word FORUM. Let me explain, it's easy: If one can and WANTS to help, he can altruistically do so, if not, it's not a problem, nobody is pointing a gun at anybody ! But repeating phrases such as "Read the manual", "Use Google" is just redundant and the only thing you accomplish is increase the number of "no-substance-just-trying-to-be-arrogant" posts
Now, syg00 may not respond to this, but I will.
Let me focus on this:
Quote:
Oh, wait, as a matter of fact, that's the first thing I did, but it doesn't seem like it helped, does it?
So, you're saying you read the man page. Really? If you did, you would have read this:
Code:
-w, --word-regexp
Select only those lines containing matches that form whole
words. The test is that the matching substring must either be
at the beginning of the line, or preceded by a non-word
constituent character. Similarly, it must be either at the end
of the line or followed by a non-word constituent character.
Word-constituent characters are letters, digits, and theunderscore.
I emphasize the last line so I can pose this question: did your regex match text that was followed by a non-word constituent character? Say, for instance, a colon? Or did your regex match too much--leaving an 'x' (which is a word-constituent character) and causing the -w test to break?
So, either (1) you didn't read it, or (2) you chose to ignore the last sentence instead of figuring it out or asking for clarification. Stop me if I'm getting any of this wrong...
As you stated, this is a forum, and someone like syg00 who (if you notice) has over 8,000 posts to his credit has undoubtedly seen many messages posted by people that (1) have not read man pages, (2) have not searched Google, and (3) immediately gave up after their first attempt didn't give perfect results.
So before you get aggressive and start throwing mud, make sure that you did, in fact, read the man pages. Because, it sure looks like you didn't.
Most everyone here will be happy to help as long as we get the feeling the person on the other end is being honest and putting forward some effort of their own.
Last edited by Dark_Helmet; 11-13-2010 at 05:03 AM.
I emphasize the last line so I can pose this question: did your regex match text that was followed by a non-word constituent character? Say, for instance, a colon? Or did your regex match too much--leaving an 'x' (which is a word-constituent character) and causing the -w test to break?
So, either (1) you didn't read it, or (2) you chose to ignore the last sentence instead of figuring it out or asking for clarification. Stop me if I'm getting any of this wrong...
As you stated, this is a forum, and someone like syg00 who (if you notice) has over 8,000 posts to his credit has undoubtedly seen many messages posted by people that (1) have not read man pages, (2) have not searched Google, and (3) immediately gave up after their first attempt didn't give perfect results.
So before you get aggressive and start throwing mud, make sure that you did, in fact, read the man pages. Because, it sure looks like you didn't.
Most everyone here will be happy to help as long as we get the feeling the person on the other end is being honest and putting forward some effort of their own.
Well, the honest truth is that I read the man page... I don't know why but I didn't completely understand what "-w" was supposed to do and when it was useful(fyi, english isn't my first language). But you are right, I've been a complete jerk and I do apologise to syg00 and to everyone else. I don't usually act like this, but I was in a difficult situation for a number of reasons, and well, like I said, I DID read the manual, it's just somehow I missed that part.
Hi guys, I'm trying to find exact matches of some users in the /etc/passwd file using "grep -w", but it doesn't always work.
For example, I have the following users:
Of course it doesn't work. The correct search string is:
grep "^stewart:" /etc/passwd
It matches every line that starts with stewart and has a colon after it. It works flawlessly.
I skimmed the question and only looked at the part where u wanted to match the user name "stewart". Even if my answer was wrong it did give u the correct guideline which I'd appreciate if i were u.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.