LinuxQuestions.org
Visit Jeremy's Blog.
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 10-01-2012, 05:05 PM   #1
sethbw
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Rep: Reputation: Disabled
Regular expressions not working for grep??


Hello guys,

I'm trying to locate any template files in our file hierarchy that contain specific patterns... I'm familiar with regex... have been using it for a few years now with the assistance of regexr...

I am using Ubuntu 11.04

Now when I try using the syntax found on the man pages and many other how-to sites I never get any results, yet I know there are files with these patterns in them...

What the deal, yo?

Examples of patterns I'm using that simply do not return any results:

grep -r "radius\(" *
grep -r "maximum\-scale\=1" *
grep -r "\d+em\;" *


Any help provided on this matter is greatly appreciated.

Cheers,
S
 
Old 10-01-2012, 05:31 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2beta3 on Lenovo Thinkpad W520
Posts: 6,792

Rep: Reputation: 2136Reputation: 2136Reputation: 2136Reputation: 2136Reputation: 2136Reputation: 2136Reputation: 2136Reputation: 2136Reputation: 2136Reputation: 2136Reputation: 2136
From where did you issue the grep command? if not from the root of the tree you want to search in, try: "grep -r <pattern> /root/of/the/tree/*"
 
Old 10-01-2012, 06:56 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Quote:
I'm familiar with regex... have been using it for a few years now with the assistance of regexr...
Different regex libraries often use slightly different syntaxes for the special meta-characters.

man grep(1):
Quote:
Basic vs Extended Regular Expressions

In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \).
Also, use single quotes unless you need variable expansion:
Code:
grep -r "radius\(" *
grep -r 'radius(' *
grep -r "maximum\-scale\=1" *
grep -r 'maximum-scale=1' *
grep -r "\d+em\;" *
grep -r '[0-9]\+em;' *
 
Old 10-02-2012, 10:45 AM   #4
sethbw
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Hmmm isn't this example:

Quote:
grep -r 'radius(' *

the exact opposite of what the man page says below?
Quote:
In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \).

I did read the man page before posting here btw... it doesn't seem to make any sense.

When I try with the backslash in front of the parenthesis this is the return:

Quote:
$ grep -r 'radius\(' *
grep: Unmatched ( or \(
I am at the root where many files have multiple lines of CSS3 border-radius styles containing the exact spelling and capitalization as: "-radius(" -In fact I can look them up and open them in the folder tree using vi or nano... however this returns 0 results:

Quote:
$ grep -r 'radius(' *

Last edited by sethbw; 10-02-2012 at 10:48 AM.
 
Old 10-02-2012, 02:52 PM   #5
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
Code:
grep -r 'radius(' *
works for me with a test file.

Do you get a match with
Code:
grep 'radius' aknownfile
grep -r 'radius' *
grep 'radius(' aknownfile
etc?
 
1 members found this post helpful.
Old 10-02-2012, 03:44 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Quote:
Originally Posted by sethbw View Post
Hmmm isn't this example:
Quote:
grep -r 'radius(' *
the exact opposite of what the man page says below?

I did read the man page before posting here btw... it doesn't seem to make any sense.
The man page is very terse, but what it's saying is that in the default basic mode, a '(' will match a literal '(' in the text. You use '\(' for grouping, eg: 'Linux\(Questions\|Answers\)' matches 'LinuxQuestions' and also matches 'LinuxAnswers', 'Linux(Questions|Answers)' matches just the literal string 'Linux(Questions|Answers)'. If you use grep -E for extended mode, the sense of '\(' and '(' is reversed.

+1 to SecretCode's testing suggestions.
 
  


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
[SOLVED] Grep regular expressions rahularjun86 Linux - Newbie 5 12-03-2011 05:41 PM
[SOLVED] Regular Expressions and Grep metallica1973 Linux - General 8 03-08-2011 09:17 AM
[SOLVED] Help using wc and grep with regular expressions citygrid Linux - Newbie 12 04-17-2010 03:29 AM
[SOLVED] Why this grep command with regular expressions not working on my system? Andrew Dufresne Linux - Newbie 12 10-01-2009 03:38 PM
Regular expressions using grep linuxmandrake Programming 3 11-16-2005 05:29 PM


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