There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard mouse network printer problem ram registry router server slow software sound svchost.exe trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Grep help needed (syntax)

Reply  
Thread Tools
raeba's Avatar
Junior Member with 13 posts.
 
Join Date: Feb 2005
Experience: Advanced
15-Feb-2005, 02:54 PM #1
Arrow 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
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
15-Feb-2005, 04:10 PM #2
Pipe it to another grep command.
raeba's Avatar
Junior Member with 13 posts.
 
Join Date: Feb 2005
Experience: Advanced
15-Feb-2005, 04:28 PM #3
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
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
15-Feb-2005, 04:36 PM #4
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
raeba's Avatar
Junior Member with 13 posts.
 
Join Date: Feb 2005
Experience: Advanced
15-Feb-2005, 04:55 PM #5
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
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
15-Feb-2005, 04:58 PM #6
Do you know what the manual pages are? At a shell prompt type: man grep

Look at grep -v and grep -f.
raeba's Avatar
Junior Member with 13 posts.
 
Join Date: Feb 2005
Experience: Advanced
15-Feb-2005, 05:28 PM #7
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
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
15-Feb-2005, 05:32 PM #8
Use the -v on the second grep statement that you are piping your output to.
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
15-Feb-2005, 05:34 PM #9
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.
raeba's Avatar
Junior Member with 13 posts.
 
Join Date: Feb 2005
Experience: Advanced
15-Feb-2005, 05: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...

Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
15-Feb-2005, 06: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
raeba's Avatar
Junior Member with 13 posts.
 
Join Date: Feb 2005
Experience: Advanced
16-Feb-2005, 02: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
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
16-Feb-2005, 02: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!
deuce868's Avatar
Senior Member with 638 posts.
 
Join Date: Nov 2000
Location: MI
17-Feb-2005, 08: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...
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:35 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.