The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Operating Systems > Linux
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search files with specfic extention and later search content lovi_v UNIX for Advanced & Expert Users 2 07-14-2008 01:05 PM
how to delete content in a file (delete content only) kittusri9 Shell Programming and Scripting 5 05-15-2008 02:12 PM
shell script to search content of file with timestamps in the directory psychobeauty Shell Programming and Scripting 10 04-21-2008 06:37 AM
grep/cat/more -- search in a txt file and display content from a specific "keyword" I-1 UNIX for Dummies Questions & Answers 4 02-21-2007 04:57 AM
How to search files containing a specific word in the content amjath78 UNIX for Dummies Questions & Answers 1 01-03-2007 03:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-26-2008
satimis satimis is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 45
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
  #2 (permalink)  
Old 07-26-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,345
Use grep:


Code:
grep [option] pattern [file]

Have a read of the manpage for the options.

Regards
  #3 (permalink)  
Old 07-28-2008
gouthk gouthk is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 7
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 (permalink)  
Old 07-28-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool 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.
  #5 (permalink)  
Old 10-22-2008
satimis satimis is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 45
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0