How to search file content

Hi folks,

What will be an easy and effective way searching file content? E.G I need to find a WORD or a PHRASE on a file? TIA

B.R.
satimis

Use grep:

grep [option] pattern [file]

Have a read of the manpage for the options.

Regards

grep -iR <phrase>
<phrase> -> word you want to search if you want to search a sentence enclose within '' (single quotes)

To make your search more faster if you know what type of files to be searche use the following

find -iname "*.xml" | xargs grep -iR <phrase>

When searching for a word --
Beware of how to differentiate between "word" and "sword"
One approach would be to search for " word " (note spaces before & after), but what if the line started with the "word"?
When search for a phrase --
Can it be split on multiple lines?
If so, you may need to remove <new-line> characters before the search to make sure all text is on the same line.

There are other considerations, but without seeing the sample datafile and your anticipated search pattern, it is hard to give any more thoughts.

Hi folks,

Thanks for your advice.

I tried to find files containing the word 'namecard' on all files /path/directory;

# grep -iR namecard /media/usbdisk/Documents_2006_2008/

/media/usbdisk/Documents_2006_2008/Fedora/Server/Gani/gani_20070326.txt:pendrive and namecard CD.  The complete OS is limited to 
50MB.

The output just repeats with the mouse pointer pending there.

Could you please shed me some light what does it mean? How to proceed?

TIA

B.R.
satimis