LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-27-2012, 04:16 AM   #1
PianoLinux
LQ Newbie
 
Registered: Feb 2012
Posts: 1

Rep: Reputation: Disabled
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
 
Old 02-27-2012, 04:24 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
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
 
Old 02-27-2012, 04:31 AM   #3
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103


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

Hope this is not homework..............
 
Old 02-27-2012, 04:34 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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.
 
Old 02-27-2012, 05:19 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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.
 
Old 02-27-2012, 09:53 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by jv2112 View Post


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

Hope this is not homework..............
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

Last edited by Tinkster; 02-27-2012 at 09:54 AM.
 
Old 02-27-2012, 10:04 AM   #7
mandyapenguin
Member
 
Registered: Nov 2011
Location: India
Distribution: RedHat, Cent OS, Fedora, Debian, Ubuntu
Posts: 106

Rep: Reputation: Disabled
I hope the below can help you.
Code:
awk -F: '($5 == "") {print}' /etc/passwd
 
Old 02-27-2012, 10:52 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
Quote:
Originally Posted by Tinkster View Post
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.
 
Old 02-27-2012, 11:01 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
The isalpha man page is good too
 
Old 02-27-2012, 11:55 AM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by David the H. View Post
[: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?

Thanks for the update.
 
Old 02-28-2012, 04:34 AM   #11
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Wink

Tinkster ,

Thanks for the clarificarion !
 
Old 02-28-2012, 10:43 PM   #12
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 183
Blog Entries: 1

Rep: Reputation: 25
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
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tools to parse NMEA GPS data : grep & awk mjolnir LinuxQuestions.org Member Success Stories 0 07-19-2010 07:20 AM
[SOLVED] grep $LOGNAME /etc/passwd Dru-Jitsu Linux - Newbie 13 07-08-2010 08:50 PM
Parse error: parse error, unexpected $ in /home/content/d/o/m/domain/html/addpuppy2.p Scooby-Doo Programming 3 10-25-2007 09:41 AM
Swat uses PAM but changes linux passwd not samba passwd Peter@KKVS Linux - Networking 0 11-26-2006 04:20 AM
Need help with grep, trying to parse/filter a file... patsnip Programming 4 08-29-2003 02:33 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration