LinuxQuestions.org
Review your favorite Linux distribution.
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 04-02-2007, 05:43 AM   #1
jazzor
Member
 
Registered: Apr 2007
Posts: 41

Rep: Reputation: 16
Grep assistance


How do I use grep to match a strict pattern eg I have
"
124
1
235
456
1abc
a1bc
1-abc
1
ab 1 c
"

and I want to grep just the line(s) containing strictly "1".
grep <script> output:
1
1

If I do grep "1" I get:
123
1
1abc
a1bc
1-abc
1
ab 1 c

which is not what I want.
and if I do grep -w "1" I get:
1
1-abc
ab 1 c

which is not what I want either.
 
Old 04-02-2007, 06:10 AM   #2
tux59
LQ Newbie
 
Registered: Mar 2006
Location: New Delhi, India
Distribution: Ubuntu 6.06 LTS
Posts: 4

Rep: Reputation: 0
Lightbulb grep works with regular expressions

Linux uses powerful regular expressions in many of its tools...

Just do a
grep '^1$' filename

The pattern ^1$ is regular expression.
^ means beginning of line
1 is a character to match
$ means end of a line.

A quickstart to Regexp http://www.regular-expressions.info/quickstart.html
Learn regular expressions for powerful searching etc...
 
  


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
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 05:56 AM
grep: grep for two substrings? eur0dad Linux - General 2 08-17-2006 05:03 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 01:22 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 04:10 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