Unix/Linux Go Back    


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

How to search file content

Linux


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-26-2008
satimis satimis is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 28 January 2013, 8:25 AM EST
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 07-26-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 24 April 2015, 3:12 PM EDT
Location: The Netherlands
Posts: 7,730
Thanks: 128
Thanked 544 Times in 512 Posts
Use grep:


Code:
grep [option] pattern [file]

Have a read of the manpage for the options.

Regards
Sponsored Links
    #3  
Old Unix and Linux 07-28-2008
gouthk gouthk is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 14 October 2011, 8:42 AM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
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>
    #4  
Old Unix and Linux 07-28-2008
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 16 April 2015, 10:54 AM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,351
Thanks: 80
Thanked 160 Times in 147 Posts
Tools grep is the command, but some things to think about..

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.
Sponsored Links
    #5  
Old Unix and Linux 10-22-2008
satimis satimis is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 28 January 2013, 8:25 AM EST
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
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/
Code:
/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
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search for string in filename, not file content daflore Shell Programming and Scripting 3 04-19-2010 10:03 AM
Perl search and replace file content. jxh461 Shell Programming and Scripting 3 04-16-2009 11:26 PM
How do I search first&second string & copy all content between them to other file? pankajp Shell Programming and Scripting 12 01-07-2009 08:33 PM
Search File content. elenatec UNIX for Dummies Questions & Answers 3 09-04-2008 11:53 AM
shell script to search content of file with timestamps in the directory psychobeauty Shell Programming and Scripting 10 04-21-2008 05:37 AM



All times are GMT -4. The time now is 04:47 AM.