Jump to content

Using Grep

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
mop

mop

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
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?

#2
Crop

Crop

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
I think there is a way. Do a man grep and see what the options are.

#3
Jame

Jame

    Learning Programmer

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

grep -l


#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
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

To search all files for body:

grep body *