LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 07-24-2008, 04:48 AM   #1
kapilbajpai88
Member
 
Registered: Jul 2008
Location: Bangalore, India
Distribution: RHEL
Posts: 235

Rep: Reputation: 41
Unhappy how to search files apart from GREP??


how can i search any file on RHEL5 without using Grep command as it takes the process in pipeline and it takes hell lot of time to search a file.
do suggest any other searching command pls.

thank you all.
 
Old 07-24-2008, 05:04 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Although you can use sed or awk to search file(s), grep was specifically written to do this. I do assume that grep will be more efficient then sed/awk (or other standard tools).

Using sed:
sed -n '/<string>/p' <infile>

Using awk:
awk '/<string>/ { print }' <infile>

Anyway, hope this helps.
 
Old 07-24-2008, 05:30 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
It seems to me that the time to search a file will be dominated by the amount of disk access required---so the actual code being used might not make that much difference.
Quick experiment: Search 730Kbyte file for a single word:
grep: 0.07 sec
sed: 0.08 sec

BTW, these commands don't require piping, e.g.:
grep keyword filename
sed -n '/keyword/p' filename
 
Old 07-24-2008, 07:28 AM   #4
sir_com
Member
 
Registered: Feb 2008
Posts: 31

Rep: Reputation: 15
Yes....I too completely agree that "grep" is much more efficient than sed or awk. sed/awk are mainly designed for pattern matching.

Also, from your question I am not much clear. If you want to search a particular word/string from a file then use awk like this

awk'/pattern/{print }'<filename>

If you are trying to find a whole file frm the file system then use the find command as

find <path> -name <filename>

Cheers,
sir_com
 
Old 07-24-2008, 11:44 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by kapilbajpai88 View Post
how can i search any file on RHEL5 without using Grep command as it takes the process in pipeline and it takes hell lot of time to search a file.
do suggest any other searching command pls.

thank you all.
What are you searching for? What are you piping through
grep from?
 
Old 07-24-2008, 12:09 PM   #6
Berticus
Member
 
Registered: Jul 2005
Distribution: Arch
Posts: 159

Rep: Reputation: 31
I'm interpretting this question as "I want to find a particular file on my system" instead of "I want to find a particular string in my file."

If I'm right, then you should take a look at the find command. I would do something like:
Code:
find /my/directory -iname 'My_file*'
You can man find for more information.
 
Old 07-24-2008, 12:15 PM   #7
Chromezero
Member
 
Registered: Nov 2004
Location: Arizona
Distribution: Slackware, RHEL, others
Posts: 470

Rep: Reputation: 40
If you're looking for a file on your system, I recommend locate or slocate.
 
  


Reply

Tags
file, grep, search


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
grep search... tobiasw Linux - General 4 10-28-2006 02:36 PM
To recursively search with grep grautu Slackware 5 11-21-2005 03:53 AM
can you specify which files to grep search? sneakyimp Linux - Software 4 10-12-2005 09:28 PM
Using Grep to search all sub-directories yrraja Solaris / OpenSolaris 2 08-28-2004 04:29 AM
Grep for search, but what for replace? TheSpecial Linux - Software 18 04-28-2003 10:01 AM


All times are GMT -5. The time now is 08:59 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration