Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-23-2010, 01:48 AM   #1
Registered: Feb 2009
Posts: 37

Rep: Reputation: 15
finding words in files.


I am looking for this `struct messages_sdd_t` and I need to search through a lot of *.c files to find it. However, I can't seen to find a match as I want to exclude all the words 'struct' and 'messages_sdd_t'. As I want to search on this only 'struct messages_sdd_t' The reason for this is, as struct is used many times and I keep getting pages or search results.

The directory I am searching in, has another directories so it will have to search recursively.

I have been doing this without success:
 find . -type f -name '*.c' | xargs grep 'struct messages_sdd_t'
and this
 find . -type f -name '*.c' | xargs egrep -w 'struct|messages_sdd_t'
Many thanks for any suggestions,
Old 04-23-2010, 02:03 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
My first thought was to give you the "find .. -exec {} \;" syntax.

That would work ... but a better idea might be to acquaint you with "gid" ("id-utils").

Please do this:
1. See if you can find "id-utils" in your package manager.
Install it.
Otherwise, you can download and build the tarball from here.

2. "cd" to the top-level of your project, and type "mkid"
<= this creates an id-utils index of your entire source tree.
it just takes a few moments - even for a large project

3. Type "gid messages_sdd_t"
You should see all instances of "messages_sdd_t", including the definition.

4. You can combine "gid XYZ" with "less", "grep" and other tools easily to filter your search.
You can use id-utils with "vi" or "emacs" to lookup code directly in your text editor.

'Hope that helps .. PSM

find . -name "*.c" -exec {} grep messages_sdd_t \;
Old 04-23-2010, 04:44 AM   #3
Registered: Mar 2010
Location: Tennessee, USA
Distribution: Arch, Fedora
Posts: 59

Rep: Reputation: 18
When I try your first example, I get the expected results, so I'm not sure what is not working. You may want to try using a regular expression for more control like this:

find . -type f -name '*.c' | xargs grep -e "struct.*messages_sdd_t'
That would list any line with "struct" and then "messages_sdd_t"
Old 04-23-2010, 10:36 AM   #4
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Try id-utils. Satisfaction guaranteed


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
Removing white spaces between words and joining the words in a given format Priyabio Linux - General 4 08-20-2009 08:42 AM
copy files containing specific words in a specified line abenmao Linux - Newbie 5 08-28-2008 10:04 AM
changing words in txt files Raakh Linux - Newbie 3 11-15-2007 03:40 AM
Finding files and then finding content within those files... Maeltor Linux - Software 5 03-13-2007 01:06 PM
Search and Replace: Asian Words to English Words ieeestd802 Linux - Software 0 10-27-2004 08:48 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration