LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 10-25-2011, 02:32 AM   #1
GNakul
Member
 
Registered: Oct 2011
Location: Bangalore,India
Posts: 59

Rep: Reputation: Disabled
grep


Hi,
I have lot of .c files in a folder. I have to search for a function. I dont know in which .c file it is there. I m not familiar with the grep and find command. Pls help.


Thanks
-Nakul
 
Old 10-25-2011, 02:40 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It's worth to read the manual pages of grep, find and xargs. For a more detailed explanation of the find utility, please take a look at http://www.gnu.org/software/findutil...mono/find.html.

Regarding your issue, you can find all the *.c files recursively, starting from the current working directory, by means of
Code:
find . -name \*.c
and to pass the list of files to the grep command, you can try xargs as in
Code:
find . -name \*.c | xargs grep PATTERN
 
Old 10-25-2011, 08:36 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Or you can run this in the directory containing the source files:

Code:
grep -Rn PATTERN
 
Old 10-25-2011, 12:54 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <Linux-Newbie> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 10-26-2011, 12:22 AM   #5
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
If you want to search in c source code, it would be easier to use "cscope". Its a free software and should be available in the repo of your distro.
 
  


Reply



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
[SOLVED] Grep -p for Linux, Trying to grep a paragraph. ohijames Linux - Newbie 5 07-22-2010 02:09 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 07:12 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:39 AM.

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
Open Source Consulting | Domain Registration