Grep with unknown pattern? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Grep with unknown pattern?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-09-2013
Morridini Morridini is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 9 January 2013, 8:50 AM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Grep with unknown pattern?

Hi.

I have a small problem that I haven't been able to find out of on my own. I am not much into bash scripting, however I use grep now and then when working on my code in order to locate specific objects, so I'll just state my exact problem:

The code is huge, and has a function that is simply named "f", I want to see every instance where it is being used. It has two arguments that I don't care about, so my first attempt was to do the following:

Code:
grep "f(*,*)" */*f90

This then gave me every line in the code that ended with "f)" as well as every time we had an "f(" (meaning every if test and a billion other routines).

I'm therefore searching for a way to let grep only search for the pattern where f is followed by a left paranthesis, with two arguments I don't care about and then a right parenthesis.

Additional help would be to tell grep to ignore all the f's that have a letter preceeding it (this would let me not get all the if tests, but would also give me the instances when f is in a product (ala "*f").

Thanks in advance to any who could help me.
Sponsored Links
    #2  
Old 01-09-2013
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 July 2014, 11:07 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,663
Thanks: 182
Thanked 616 Times in 574 Posts
Something like this may work:

Code:
grep -E '\<f\([^),]+,[^),]+\)' */*f90

-E - for extended regular expressions (the + quantifier is part of the EREs)
\< - GNU word boundary - \< matches at the start of a word, note that some grep implementations support the \b syntax.
[^...] - negated character class - match everything but the characters in the list - in this case everything that's not ) or , .
+ - one or more of the preceding pattern - one or more character that's neither ) nor , .

Hope this helps.
The Following User Says Thank You to radoulov For This Useful Post:
Morridini (01-09-2013)
Sponsored Links
    #3  
Old 01-09-2013
Morridini Morridini is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 9 January 2013, 8:50 AM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks, that worked like a charm.

And doubly thanks for explaining all the terms rather than giving me a solution (that looks really complicated at first glance).
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep the word from pattern line and update in subsequent lines till next pattern line reached rbalaj16 Shell Programming and Scripting 5 06-18-2012 04:39 AM
grep unknown number of params GmGeubt Shell Programming and Scripting 8 10-02-2011 02:48 PM
Replace line with found unknown pattern joas UNIX for Dummies Questions & Answers 5 10-07-2010 04:20 AM
Want to grep for a pattern and display the content above that pattern ajayakunuri Shell Programming and Scripting 6 06-25-2010 06:48 AM
Grep to match unknown pattern mrchilly Shell Programming and Scripting 4 10-27-2009 01:27 PM



All times are GMT -4. The time now is 12:13 AM.