Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Using Grep


  • Please log in to reply
3 replies to this topic

#1 mop


    CC Regular

  • Just Joined
  • PipPipPip
  • 30 posts

Posted 06 April 2008 - 05:07 PM

I often use

cat *.txt | grep <search>

which will list all of the occurances of a string in the files with .txt extension. But the output isn't what I need.

I need to know which files the search string was actually in. Is there a way in cat or grep to output the filename?
  • 0

#2 Crop


    CC Resident

  • Just Joined
  • PipPipPipPip
  • 59 posts

Posted 06 May 2008 - 01:43 PM

I think there is a way. Do a man grep and see what the options are.
  • 0

#3 Jame


    CC Regular

  • Just Joined
  • PipPipPip
  • 29 posts

Posted 19 May 2008 - 10:48 AM

I had a look at the man pages and you should be able to use the '-l' option to list filenames.

grep -l

  • 0

#4 Guest_Jordan_*

  • Guest

Posted 31 May 2008 - 07:52 AM

Use it like this (rather than using CAT in combination with it):

# grep <word> <file>

IE, to search all .php for body

grep body *.php

To search all files for body:

grep body *

  • 0

Also tagged with one or more of these keywords: grep

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download