Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Using Grep

grep

  • Please log in to reply
3 replies to this topic

#1 mop

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

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

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_Jordan_*
  • Guest

Posted 31 May 2008 - 07:52 AM

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

# grep <word> <file>
[code]

IE, to search all .php for body

[code]
grep body *.php
[/code]

To search all files for body:

[code]
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