Go Back   Linux Forums by TotalPenguin! Get linux Help! > Linux > Linux General

Linux General Any questions that are not covered by other forums go here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-2008, 02:07 AM
mop mop is offline
Junior Member
 
Join Date: Apr 2008
Posts: 17
mop is on a distinguished road
Default Using Grep

I often use

Code:
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?
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-06-2008, 10:43 PM
Member
 
Join Date: Jan 2007
Posts: 62
Crop is on a distinguished road
Default

I think there is a way. Do a man grep and see what the options are.
Reply With Quote
  #3 (permalink)  
Old 05-19-2008, 07:48 PM
Member
 
Join Date: Feb 2008
Posts: 32
Jame is on a distinguished road
Default

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

Code:
grep -l
Reply With Quote
  #4 (permalink)  
Old 05-31-2008, 04:52 PM
Jordan's Avatar
Administrator
 
Join Date: Nov 2006
Posts: 570
Jordan is on a distinguished road
Default

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

[code]
# grep <word> <file>
[code]

IE, to search all .php for body

Code:
grep body *.php
To search all files for body:

Code:
grep body *
Reply With Quote
Reply

Tags
grep

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:43 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.