View previous topic :: View next topic |
Author |
Message |
cyberfunk007 n00b
Joined: 11 Oct 2002 Posts: 23
|
Posted: Thu Jun 05, 2003 11:36 pm Post subject: Scripting Question |
|
|
Hi,
I have a list of 200 or so names in the following format in a text file.
joe bloggs
harry potter
smelly smith
I need to grep all of those names and see which ones exist in the password file /etc/passwd.
I would like the names that actually exist to be directed to an output file so I can see exactly who has access out of that list. I have tried numerous things but I cant seem to get the format right. I am a newb! lol and I am also using the POSIX shell.
Any help would be GREATLY appreciated as I need this done in 5 hours.
Thanks in advance
Cyber |
|
Back to top |
|
|
aja l33t
Joined: 26 Aug 2002 Posts: 705 Location: Edmonton, Canada
|
Posted: Fri Jun 06, 2003 1:06 am Post subject: |
|
|
I think xargs is what you are looking for (you can get it to use the same command on every line of standard input.) Piping from cat lets you use the file as input:
Code: |
cat names.txt | xargs -i grep '{}' /etc/passwd
|
Redirect output to a file will give you all the matching lines from passwd
You could get fancier using sed (instead of cat) to process the input stream using a regular expression and using awk to process the output into a pretty format. |
|
Back to top |
|
|
cyberfunk007 n00b
Joined: 11 Oct 2002 Posts: 23
|
Posted: Fri Jun 06, 2003 1:57 am Post subject: |
|
|
Thanks for that,
I tried the syntax above, but it did not work. I got the following error message
Code: | [root@melhpux1] /home/beala01-> cat names.txt | xargs -i grep '{}' /etc/passwd
xargs: missing quote?: Bernie OBrien
[root@melhpux1] /home/beala01->
|
Any ideas what I have done wrong?
Thanks in advance
Cyber |
|
Back to top |
|
|
aja l33t
Joined: 26 Aug 2002 Posts: 705 Location: Edmonton, Canada
|
Posted: Fri Jun 06, 2003 2:06 am Post subject: |
|
|
You have the name "Bernie O'Brien" in your text file. The single quote is screwing it up. Change to Bernie O''Brian (or is it Bernie O\'Brien?) or use sed to change on the fly. |
|
Back to top |
|
|
cyberfunk007 n00b
Joined: 11 Oct 2002 Posts: 23
|
Posted: Fri Jun 06, 2003 3:47 am Post subject: |
|
|
Hi,
I am still having no luck I am not that good at using sed and cant get it to work properly...
Any other ideas would be great.
Cyber |
|
Back to top |
|
|
aja l33t
Joined: 26 Aug 2002 Posts: 705 Location: Edmonton, Canada
|
Posted: Fri Jun 06, 2003 4:23 am Post subject: |
|
|
First, confirm my diagnosis (I have been wrong before) by removing names with characters like ('), and post your results. If it works for 'normal' names, we can work on dealing with special cases. |
|
Back to top |
|
|
|