LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to search files apart from GREP?? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-search-files-apart-from-grep-657891/)

kapilbajpai88 07-24-2008 03:48 AM

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.

druuna 07-24-2008 04:04 AM

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.

pixellany 07-24-2008 04:30 AM

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

sir_com 07-24-2008 06:28 AM

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

Tinkster 07-24-2008 10:44 AM

Quote:

Originally Posted by kapilbajpai88 (Post 3224646)
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?

Berticus 07-24-2008 11:09 AM

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.

Chromezero 07-24-2008 11:15 AM

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


All times are GMT -5. The time now is 10:35 PM.