LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to parse /etc/passwd by means of grep? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-parse-etc-passwd-by-means-of-grep-931513/)

PianoLinux 02-27-2012 04:16 AM

How to parse /etc/passwd by means of grep?
 
hi guys
plz plz help me in this query in Redhat Linux
in the /etc/passwd file
i need to find the rows where column 5 is empty
using only grep
there is a pattern in all lines where column 5 is empty: the first column in all of them is either letters or numbers, the second is always x, the third is numebrs and the fourth is numbers
plz help me guys and ASAP
thanks a lot

EricTRA 02-27-2012 04:24 AM

Hello and welcome to LinuxQuestions,

First of all, please spell out your words, text speak is not appreciated on LQ forums. Besides that this sound a lot like homework and although it's not against the LQ Rules to ask for help with homework, you shouldn't post it verbatim nor should you expect us to do the work for you. We'll be glad to point you in the right direction if you show us what you've already figured out and where it's failing. And as a last point, don't ask for privileged attention, it's only urgent to you, not to us who are all volunteers here.

A good starting point is Google and the man page for grep
Code:

man grep
Looking forward to your participation in the forums. Have fun with Linux.

Kind regards,

Eric

jv2112 02-27-2012 04:31 AM

:twocents:

Code:


grep -n [[:blank:]] /etc/passwd


Hope this is not homework.............. :rolleyes:

catkin 02-27-2012 04:34 AM

Your problem is only urgent to you, not to the volunteers who give their time freely to answer questions.

Why can you only use grep? That sounds like a homework question. Bash and awk are more naturally suited to the task.

colucix 02-27-2012 05:19 AM

Please use a descriptive title for your thread excluding words like 'urgent' or 'help'. Using a proper title makes it easier for members to help you. This thread has been reported for title modification. Please do not add replies that address the thread title.

Tinkster 02-27-2012 09:53 AM

Quote:

Originally Posted by jv2112 (Post 4613024)
:twocents:

Code:


grep -n [[:blank:]] /etc/passwd


Hope this is not homework.............. :rolleyes:

Not that "blank" is actually a character class, but ...

That most likely won't do what (s)he wants anyway. In terms of
the password field "blank" usually means nothing, not "any
amount of whitespace".

A more likely candidate:
Code:

grep -E "^..*:..*:..*:..*:[[:space:]]*:.*" /etc/passwd

Cheers,
Tink

mandyapenguin 02-27-2012 10:04 AM

I hope the below can help you.
Code:

awk -F: '($5 == "") {print}' /etc/passwd

David the H. 02-27-2012 10:52 AM

Quote:

Originally Posted by Tinkster (Post 4613225)
Not that "blank" is actually a character class, but ...

[:blank:] is indeed a character class. It consists of <space> and <tab> only, as opposed to [:space:], which contains <space>, <tab>, <newline>, <vertical tab>, <form feed>, and <carriage return>.

The best description I've found of all the character classes is in the grep info page.

catkin 02-27-2012 11:01 AM

The isalpha man page is good too

Tinkster 02-27-2012 11:55 AM

Quote:

Originally Posted by David the H. (Post 4613274)
[:blank:] is indeed a character class. It consists of <space> and <tab> only, as opposed to [:space:], which contains <space>, <tab>, <newline>, <vertical tab>, <form feed>, and <carriage return>.

The best description I've found of all the character classes is in the grep info page.

Far out :}

Don't you hate it when man & info are out of sync like that? :D

Thanks for the update.

jv2112 02-28-2012 04:34 AM

Tinkster ,

Thanks for the clarificarion !

lisle2011 02-28-2012 10:43 PM

An answer but not grep
 
#!/bin/bash

for j in $(cut -f "some numbers defining the text positions in -f": /etc/password)

Page 162 in Learning the bash shell by Cameron Newham & Bill Rosenblatt. Your answer is there.




I I have helped in any way give me a pat on the back (add to my reputation)

Learn the Bash shell and all will be well.


If I have helped you in any way give me a pat on the back (add to my reputation)

D


All times are GMT -5. The time now is 09:49 PM.