 | Junior Member with 13 posts. | | Join Date: Feb 2005 Experience: Advanced | | Grep help needed (syntax) Hi.
I am trying to get my command line string correct to find a url (string of text) in all the files below a certain directory on the server.
Here's what I've been typing...
fgrep -i -r 'foobar' /home/* > found.txt
However, I want to skip log files (that end in log and processed) and I only want output of the filenames that the string (foobar) appears in, I don't want the output file to have the actual example of the appearance (just the dir/filenames).
So, how can I do this so that I'll find 'foobar' in all the files, except logs, processed logs, and perhaps exclude *.gz too, with the output showing only the names of files that foobar appears in (one per line)?
Thanks a bunch.
Hugs,
Raeba | | Distinguished Member with 14,984 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | Pipe it to another grep command. | | Junior Member with 13 posts. | | Join Date: Feb 2005 Experience: Advanced | | Quote: |
Originally Posted by LwdSquashman Pipe it to another grep command. | I'm new to this command, please type me out a command line that will do what I need.
Thanks a lot for your help.
Raeba | | Distinguished Member with 14,984 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | A pipe just outputs the output of one command to another command. So all you have to do is use the pipe | to output your current grep statement to another grep statement to filter out what you dont want.
grep | grep | | Junior Member with 13 posts. | | Join Date: Feb 2005 Experience: Advanced | | Quote: |
Originally Posted by LwdSquashman A pipe just outputs the output of one command to another command. So all you have to do is use the pipe | to output your current grep statement to another grep statement to filter out what you dont want.
grep | grep | I understand the pipe indicator (|). I don't know how to exclude et cetera. If someone would could type out a command line string for me, based upon the above, I'd appreciate it.
Raeba | | Distinguished Member with 14,984 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | Do you know what the manual pages are? At a shell prompt type: man grep
Look at grep -v and grep -f. | | Junior Member with 13 posts. | | Join Date: Feb 2005 Experience: Advanced | | Quote: |
Originally Posted by LwdSquashman Do you know what the manual pages are? At a shell prompt type: man grep
Look at grep -v and grep -f. | I'm already calling -f by using fgrep. The -v swtich is for selecting an inversion, which has nothing to do with what I am trying to do.
Thanks for trying. Any one esle care to give an entire command syntax statement for me (based upon my needs shown above)?
Raeba | | Distinguished Member with 14,984 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | Use the -v on the second grep statement that you are piping your output to. | | Distinguished Member with 14,984 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | Quote: |
Originally Posted by raeba I'm already calling -f by using fgrep. The -v swtich is for selecting an inversion, which has nothing to do with what I am trying to do.
Thanks for trying. Any one esle care to give an entire command syntax statement for me (based upon my needs shown above)?
Raeba | fgrep is the same as grep -F not grep -f. | | Junior Member with 13 posts. | | Join Date: Feb 2005 Experience: Advanced |
15-Feb-2005, 04:45 PM
#10 | LwdSquashman, I think I know what you meant now about the -v ... Anyway, I am still trying to get a command line going here... | | Distinguished Member with 14,984 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! |
15-Feb-2005, 05:06 PM
#11 | Ok, I was trying to help you by making you think but some people just want the answer. When I learned Linux several years go, my class was taught by this little Italian guy who would never give us the answers to anything. He would sit down with you and help you find the answer but would never give you the answer directly.
So I think this will do what you want to do.
Create a file with the file extensions you dont want included. One file extension on each line. Use that filename in your second grep statement.
.gz
.log
.whatever
fgrep -l -i -r 'foobar' /home/* | grep -f filename -v | | Junior Member with 13 posts. | | Join Date: Feb 2005 Experience: Advanced |
16-Feb-2005, 01:03 PM
#12 | Quote: |
Originally Posted by LwdSquashman Ok, I was trying to help you by making you think but some people just want the answer. When I learned Linux several years go, my class was taught by this little Italian guy who would never give us the answers to anything. He would sit down with you and help you find the answer but would never give you the answer directly.
So I think this will do what you want to do.
Create a file with the file extensions you dont want included. One file extension on each line. Use that filename in your second grep statement.
.gz
.log
.whatever
fgrep -l -i -r 'foobar' /home/* | grep -f filename -v |
I am not trying to "learn" (as in a classroom) anything in Linux or it's command per se. I just need to get past this one thing, to get something much more important done.
It will probably be the last time I will ever grep for anything...in my case.
Thanks for the time and help. By the way, it saves bandwidth to just to ignore the message or actually answer it -- so that a thread doen't linger on - serving no purpose for the one who posted it (or future readers with same issue). Enough said.
Thanks again.
Raeba | | Distinguished Member with 14,984 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! |
16-Feb-2005, 01:32 PM
#13 | Quote: |
Originally Posted by raeba By the way, it saves bandwidth to just to ignore the message or actually answer it -- so that a thread doen't linger on - serving no purpose for the one who posted it (or future readers with same issue). Enough said.
Thanks again.
Raeba  | Trivial! | | Senior Member with 638 posts. | | Join Date: Nov 2000 Location: MI |
17-Feb-2005, 07:02 AM
#14 | Anyone not using grep more than once on a linux machine is doing a lot of things the hard way.
oops, wasted bandwith... |  THIS THREAD HAS EXPIRED.
Are you having the same problem?
We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.
|
Smart Search
| Find your solution! | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |  WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
| You Are Using: |
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 07:23 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. | |
|