LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-12-2012, 08:04 PM   #1
teorxv102
LQ Newbie
 
Registered: Nov 2012
Posts: 5

Rep: Reputation: Disabled
how to find exact results from grep


My question is if i use a grep to find a statement from /etc/default/password
what coding should i need if /etc/default/passwd is 'passlength=' which is empty right after = because grep always takes the any stuff that matches it like 'passlength=2'.

heres my coding
if grep 'PASSLENGTH=' /etc/default/passwd
then
echo exception Yes
else
echo exception No
fi
Thanks in advance
 
Old 11-12-2012, 08:34 PM   #2
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 498

Rep: Reputation: 214Reputation: 214Reputation: 214
Assuming there's an end-of-line right after 'PASSLENGTH=', you can use

Code:
grep 'PASSLENGTH=$' ...
 
Old 11-12-2012, 08:44 PM   #3
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Jessie
Posts: 592

Rep: Reputation: 119Reputation: 119
Please use code tags around your codes. It preserves formatting and makes it easier to read.

Form the regex accordingly. I'm assuming passlength= starts on a new line and has nothing after it, ie:

Code:
cat /etc/default/password
passlength=
Try:
Code:
grep "^passlength=$" /etc/default/password
You may also wish to use the --quiet option to grep to suppress printing of any matching lines if using it a script.
 
Old 11-12-2012, 08:48 PM   #4
teorxv102
LQ Newbie
 
Registered: Nov 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank you both of you. It works now.
 
Old 11-12-2012, 08:51 PM   #5
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Jessie
Posts: 592

Rep: Reputation: 119Reputation: 119
Looking at your previous thread, you may want to read up on regex's. Here's a start:http://www.grymoire.com/Unix/Regular.html
 
Old 11-12-2012, 09:14 PM   #6
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
Her's another link http://etext.lib.virginia.edu/servic...nix/regex.html
 
  


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
Using grep to find EXACT MATCH andy2008 Programming 13 11-16-2010 06:48 AM
grep the exact string only ZAMO Linux - General 11 08-28-2008 05:08 AM
grep exact letters packets Linux - Newbie 1 11-30-2007 08:39 PM
grep [exact phrase] chrisfirestar Linux - General 2 02-09-2004 04:30 AM
Please help - Unpridictable results from grep/ps to find pid nharnwal Solaris / OpenSolaris 1 12-10-2003 08:28 PM


All times are GMT -5. The time now is 02:47 AM.

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