LinuxQuestions.org
Review your favorite Linux distribution.
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-12-2009, 09:33 AM   #16
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49

to pixellany
What a nice repertoire of books to learn linux.
MY QUESTION
How can i search files in subfolders which contain my pattern in their content.As I have observed does not happen in

grep pattern *
 
Old 10-12-2009, 06:16 PM   #17
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As mentioned previously, use the -r (recursive option) see http://linux.die.net/man/1/grep
 
Old 10-14-2009, 08:09 AM   #18
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
To Doculus,
grep -i pattern -r
hangs up the terminal with blinking cursor & no result.
Though 'grep -i pattern * -r' works well.
and 'grep -i pattern * -rc' shows the number of lines in which word occurs(line may contain multiple times but counted one).So i think you forgot adding * in your post.

Last edited by sumeet inani; 11-05-2009 at 06:28 AM.
 
Old 11-03-2009, 08:07 AM   #19
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
find . | xargs grep -i pattern

Can you explain the working of this command.I read man page of xargs but did not understand its role here.
 
Old 11-03-2009, 08:38 AM   #20
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by sumeet inani View Post
find . | xargs grep -i pattern

Can you explain the working of this command.I read man page of xargs but did not understand its role here.
Loosely, xargs takes the input and causes it to be used as an argument list by the next command.

Example:
Code:
[mherring@Ath play]$ find . |grep brown
[mherring@Ath play]$ find . |xargs grep brown
./words:brown
[mherring@Ath play]$ grep brown *
words:brown
In the first case, grep just looks in the filename, with xargs it reads the files---just as if the third case was used.
 
Old 11-09-2009, 07:46 AM   #21
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
Solution for finding word in files

SOLUTION FOR ALL

if you want to find a word in folder without including subfolders then
grep -i pattern *

If you want to find word in folder & search recursively in subfolders then
grep -r -i pattern *

You can add -c option in above if you only want the count of lines containing the pattern in files(NOTE that pattern appearing twice or more times in a line counts to only one)

If my compilation helps you then thank me by pressing thumbs up button (in the same way i have thanked all post on this thread found useful).Thank You.

Last edited by sumeet inani; 12-17-2009 at 11:59 PM.
 
  


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
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Web Development --- Command to search string through files on a server mobby1982 Programming 2 04-11-2009 06:14 PM
Need to search all files for string - strings command? jmur Programming 4 03-28-2008 02:35 PM
Word search Alien_Hominid Slackware 5 04-19-2006 05:52 AM
I have a harddrive that I want to search for deleted word files, what do I do first? abefroman Linux - Security 2 07-31-2005 07:37 PM

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

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