Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Scripting Question
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
cyberfunk007
n00b
n00b


Joined: 11 Oct 2002
Posts: 23

PostPosted: Thu Jun 05, 2003 11:36 pm    Post subject: Scripting Question Reply with quote

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
View user's profile Send private message
aja
l33t
l33t


Joined: 26 Aug 2002
Posts: 705
Location: Edmonton, Canada

PostPosted: Fri Jun 06, 2003 1:06 am    Post subject: Reply with quote

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
View user's profile Send private message
cyberfunk007
n00b
n00b


Joined: 11 Oct 2002
Posts: 23

PostPosted: Fri Jun 06, 2003 1:57 am    Post subject: Reply with quote

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
View user's profile Send private message
aja
l33t
l33t


Joined: 26 Aug 2002
Posts: 705
Location: Edmonton, Canada

PostPosted: Fri Jun 06, 2003 2:06 am    Post subject: Reply with quote

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
View user's profile Send private message
cyberfunk007
n00b
n00b


Joined: 11 Oct 2002
Posts: 23

PostPosted: Fri Jun 06, 2003 3:47 am    Post subject: Reply with quote

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
View user's profile Send private message
aja
l33t
l33t


Joined: 26 Aug 2002
Posts: 705
Location: Edmonton, Canada

PostPosted: Fri Jun 06, 2003 4:23 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum