LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   help with REGULAR EXPRESSIONS (https://www.linuxquestions.org/questions/linux-general-1/help-with-regular-expressions-108779/)

ner 10-26-2003 03:17 PM

help with REGULAR EXPRESSIONS
 
I need commands for finding duplicate uid's and logins in the /etc/passwd file. I have a suggestion to use cut, sort and uniq, but I have no clue how to put all this together.
thnx in advance
:)

yapp 10-27-2003 03:05 AM

please post your script, I'd like to see it myself. :)

have you tried using "sort | uniq" already?

ner 10-27-2003 08:54 AM

thank you for your reply, I will try playing with piping :)

no, didn't try anything yet, because I did not know where to start. I know that uniq can replace duplicate entries or something like that, but I do not need it replaced, just found.. We just started regular expressions, globing and all that, and we got stuck on this question..

yapp 10-27-2003 11:31 AM

I have a kind of fealing this is some homework excersise :p :rolleyes:

try to read the manual pages; "man cut" is a good start, and you'll quickly discover how to fetch the first field of the /etc/passwd file ;)

btw I don't know how this question is related to regular expressions :confused:

ner 10-27-2003 02:39 PM

I don't know how it relates to regular expressions eiter, but it came in the regular expressions lab.. We were able to solve all the rest of the problems but this one.. :(

thanks for your help, I will try it after I come back from college tonight, because I have until tomorrow to turn it in :)

yapp 10-27-2003 03:35 PM

hehe :) good luck with your excersise.

regular expressions can be used for pattern matching. (some advanced text search) guess you don't need it here, since you just want the first field.

just one little advice: Just start with small commands, and see what results you get, then add more and more options to see how the data steam changes (until you have the desired effect), and add another command in the pipe.

KDE4me 10-28-2003 12:22 AM

If you want a command I suggest ckpasswd/chkgroup otherwise as said preiously cut paste etc. or awk.

ner 10-28-2003 10:55 AM

thanks KDE4me, I will try that too :)

kev82 10-28-2003 11:13 AM

i can do it but not without writing to a file, if anyone can do it just with pipes all in one statement i'd like to know how.

yapp 10-28-2003 12:41 PM

all right... (though I still have the fealing I'm doing someones homework)

And indeed, all you need it cut. sort, and uniq. :p
Code:

cut -f 1 -d ':' < /etc/passwd | sort | uniq -d
and if you'd like to win the "unless use of cat award"
Code:

cat /etc/passwd | cut -f 1 -d ':' | sort | uniq -d
(but I think this is a bit easier to understand)

ner 10-28-2003 12:52 PM

thank you yapp!! :) works great! Hving this line, I can figure out how to do the same for UIDs (or at least I hope so :) )

unSpawn 10-28-2003 12:55 PM

We were able to solve all the rest of the problems but this one (...) because I have until tomorrow to turn it in
Ner, I am under the impression we're helping you to complete your assignments. LQ has rules against asking for ready made answers where homework is concerned. This doesn't necessarily mean we're against helping you with your homework, but assignments are made to test your skills, ingenuity and knowledge. If you can show what you're sposed to do by posting idea's or scripts, then it's all OK. Asking for ready made answers on LQ for assignments is no substitute for learning.

Please address this issue now before adding new or replying to threads.

ner 10-28-2003 01:12 PM

Whith all due respect, how do I address it?

unSpawn 10-28-2003 01:36 PM

Whith all due respect, how do I address it?
- by understanding the LQ rules on homework, and
- by acknowledging you next time should post examples of what you tried and where you failed.

As moderator all I have to add is you should understand the difference: LQ members will help you by thinking with you about solving your problem, we just don't want to do your homework for you, that's all...

ner 10-28-2003 01:41 PM

great, I do not want LQ members to do my homework for me either, all I need are examples and ideas. :)

By the way, even though I am not sure yet why we need < in the cut -f 1 -d ':' <..., I figured out how to do uids- put 3 instead of one, because the uid is the third field :)
Thanks again yapp


All times are GMT -5. The time now is 02:15 PM.