LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-05-2010, 06:35 AM   #1
HarryBoy
Member
 
Registered: Apr 2008
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215

Rep: Reputation: 16
grep question


when I grep for a word in a file like so:
grep -r wordiwanttofind ./

I get the following results:

Binary file ./libmediadatabase/getMaxSessionNo.o matches
Binary file ./libmediadatabase/libmediadatabase.a matches
./libmediadatabase/getMaxSessionNo.cpp:int MyFile::wordiwanttofind(camIndex )
Binary file ./libmediadatabase/libmediadatabase.so.1 matches
Binary file ./veapi/script/encoder/libmediadatabase.so.1 matches
Binary file ./veapi/script/recorder/libvecgiutils.so.1 matches
Binary file ./veapi/script/recorder/libmediadatabase.so.1 matches

How can I just grep for the word in .h and .cpp files??

Thanks
 
Old 08-05-2010, 07:00 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by HarryBoy View Post
when I grep for a word in a file like so:
grep -r wordiwanttofind ./

I get the following results:

Binary file ./libmediadatabase/getMaxSessionNo.o matches
Binary file ./libmediadatabase/libmediadatabase.a matches
./libmediadatabase/getMaxSessionNo.cpp:int MyFile::wordiwanttofind(camIndex )
Binary file ./libmediadatabase/libmediadatabase.so.1 matches
Binary file ./veapi/script/encoder/libmediadatabase.so.1 matches
Binary file ./veapi/script/recorder/libvecgiutils.so.1 matches
Binary file ./veapi/script/recorder/libmediadatabase.so.1 matches

How can I just grep for the word in .h and .cpp files??

Thanks
try the -I flag with your commmand.

Code:
grep -Ir


or specify the files you wish to search.


Code:
grep -r  string  *.h *.cpp

Last edited by centosboy; 08-05-2010 at 07:02 AM.
 
Old 08-06-2010, 11:49 AM   #3
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 211

Rep: Reputation: 67
when the shell's globbing isn't enough use find and xargs to generate the command line. Like so:

Code:
find . -type f \( -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep /stringiwanttofind/
zsh's globbing is far more capable than bash's. There, just `grep /foo/ **/*.{cpp,h}` would have done it.
 
  


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
grep question torrent478 Linux - Newbie 2 10-08-2008 07:50 PM
grep question tokernizer Programming 2 12-20-2005 09:02 AM
grep question djgerbavore Linux - Newbie 7 07-07-2004 08:11 AM
grep question vasanthraghavan Programming 3 04-23-2004 01:32 AM
grep question keyops Programming 2 04-09-2004 10:17 PM


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