LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find a String in Multiple Files (https://www.linuxquestions.org/questions/linux-newbie-8/find-a-string-in-multiple-files-4175419012/)

raihan26 07-27-2012 10:17 PM

Find a String in Multiple Files
 
I am new to Unix/Linux world, I am working with Hadoop. And I need to find a String in more than 100 files. And also which files contains that particular String. So below is my scenario-

So I go to Bash Prompt, and then I type like below to get all the files under a folder and it is like around 100 files under real-time folder.

Code:

bash-3.00$ hadoop fs -ls /apps/hdmi-technology/b_apdpds/real-time
So I am showing only two files that I will be getting from the above command but we have more than 2 and it is around 100 files.

Code:

-rw-r--r--  3 b_apdpds hdmi-technology 1073741824 2012-07-18 22:50 /apps/hdmi-technology/b_apdpds/real-time/HADOOP_REALTIME_consolidated_RT_v1x0_20120716_aa
-rw-r--r--  3 b_apdpds hdmi-technology 1073741824 2012-07-18 22:50 /apps/hdmi-technology/b_apdpds/real-time/HADOOP_REALTIME_consolidated_RT_v1x0_20120716_ab

And I need to find a String named
Code:

bcd4bc3e1380a56108f486a4fffbc8dc
in all of the 100 files and also which files contain that particular String. Is this possible to do it?

towheedm 07-28-2012 01:35 AM

Could it be that the other 98 files are hidden files? Try ls with the -a option to show hidden files also.

To search files for a particular string, you can use the grep command.
Code:

grep "bcd4bc3e1380a56108f486a4fffbc8dc" /apps/hdmi-technology/b_apdpds/real-time/*
See the manpages for additional info on grep.
Code:

man grep
Hope this helps.

eyanu 07-28-2012 02:39 AM

grep -R "bcd4bc3e1380a56108f486a4fffbc8dc" /path/to/folder/*

divyashree 07-28-2012 04:04 AM

Hi Raihan, Welcome to LQ.

You can use find :

Code:

find "/apps/hdmi-technology/b_apdpds/real-time" -type f -exec grep -il "bcd4bc3e1380a56108f486a4fffbc8dc" {} \;


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