• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Another Solaris/UNIX search question...

Jumpem

Lifer
How do I search a directory tree for a string? I have a particular function being called, but don't know where it is defined. How can I search for "myfunction(*)"?
 
Originally posted by: n0cmonkey
grep

find . -exec grep 'myfunction(*)' {} \;

As long as you want to search for myfunction(*) exaclty. 😛

I want it to match the function name exactly, but match anything inside the ().
 
Originally posted by: Jumpem
Originally posted by: n0cmonkey
grep

find . -exec grep 'myfunction(*)' {} \;

As long as you want to search for myfunction(*) exaclty. 😛

I want it to match the function name exactly, but match anything inside the ().

That's more difficult. Try:

find . -exec grep 'myfunction(' \;
 
Not to sound too harsh, but if you don't know regular expressions already it'll probably take longer to create one than to search for generic 'functionname' and sort through the dups.

The egrep man page has a small section on regular expressions, but there is also the perlre, perlretut and perlfaq6 man pages that describe regular expressions. There's also an O'Reilly book or two on the subject. They're incredibly useful, especially in perl, but they're also really hard to read.
 
Originally posted by: Nothinman
Not to sound too harsh, but if you don't know regular expressions already it'll probably take longer to create one than to search for generic 'functionname' and sort through the dups.

The egrep man page has a small section on regular expressions, but there is also the perlre, perlretut and perlfaq6 man pages that describe regular expressions. There's also an O'Reilly book or two on the subject. They're incredibly useful, especially in perl, but they're also really hard to read.

I know regular expressions enough to get by... I'm a bit rusty. My problem is how to get it to search through a directory tree; not just the current one.
 
Originally posted by: Nothinman
And you probably also want to use -type f, so it only runs on real files.

I can manage to grep a single file, and use find to find a list of files; but my syntax isn't right for combining the two.

I am trying to use "find /home/a/b/ -exec grep -n 'function' ".

 
That's because you didn't specify the exec arguments properly. You need to use {} which is a place holder for the filename and end the command with a semi-colon, but since most shells use semi-colons to seperate commands you have to escape it, just like n0c did in his first example.
 
find . -name "*.c" -exec grep -il functionname {} \;

i ignores case, and l will list the filename - otherwise you'll just get the line on it returned. Not much help when you're looking for the file.
 
Back
Top