Home Man
Today's Posts

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Grep with unknown pattern?

👤 Login to reply

Thread Tools Search this Thread
# 1  
Old 01-09-2013
Grep with unknown pattern?


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:
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.
# 2  
Old 01-09-2013
Something like this may work:
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)
# 3  
Old 01-09-2013
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).
👤 Login to reply

« Previous Thread | Next 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 -v lines starting with pattern 1 and not matching pattern 2 demmel UNIX for Dummies Questions & Answers 8 07-18-2015 11:59 AM
Grep lines before a pattern having some other pattern dips_ag Shell Programming and Scripting 5 02-07-2015 01:31 PM
sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3 breezevinay Shell Programming and Scripting 5 06-12-2014 02:42 AM
How to Grep than scan line below grep pattern umarsatti Shell Programming and Scripting 14 10-04-2013 02:30 PM
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
PING - Unknown host, Unknown host localhost - Solaris 10 Przemek Solaris 4 05-26-2008 12:11 AM

All times are GMT -4. The time now is 06:03 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
Show Password