Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Grep on seeming to work...

Grep on seeming to work...
Thread Tools
Mac Elite
Join Date: Feb 2002
Location: Hilton Head, SC
Status: Offline
Reply With Quote
Jul 24, 2003, 07:40 PM
 
I was trying to use the grep function this morning and it seemed to just hang there... the command I used was: grep -i finder

not sure what happened... am I doing this correctly?
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 24, 2003, 09:00 PM
 
Originally posted by Tyler McAdams:
I was trying to use the grep function this morning and it seemed to just hang there... the command I used was: grep -i finder

not sure what happened... am I doing this correctly?
The pattern for grep is

Code:
grep pattern file
Yoy passed "grep pattern" but did not specify a file, so it was trying to grep standard input.

Try something like "grep -i finder *"
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Mac Elite
Join Date: Feb 2002
Location: Hilton Head, SC
Status: Offline
Reply With Quote
Jul 24, 2003, 09:54 PM
 
Originally posted by Arkham_c:
The pattern for grep is

Code:
grep pattern file
Yoy passed "grep pattern" but did not specify a file, so it was trying to grep standard input.

Try something like "grep -i finder *"
So i need a space and an astric after the file name I'm trying to find?
     
Senior User
Join Date: Dec 2001
Status: Offline
Reply With Quote
Jul 24, 2003, 10:22 PM
 
Originally posted by Tyler McAdams:
So i need a space and an astric after the file name I'm trying to find?
grep doesn't search for file names, it searches the contents of files. The asteric is a shell "glob" character which basically says "match all file names in the current directory. Therefore, 'grep -i finder *' run from your home directory will search any file in the root of your home directory for the string 'finder', case-insensitively. You might want to try 'cd /; grep -r -i finder *'. The cd will take you to the top level of the filesystem, and the '-r' will tell grep to recursively search all directories, so you won't just be limited to the top level of your hard drive. Of course, to save time, perhaps cd to the directory you are trying to search.

If you are looking to search by file name, check out the find command instead.
"Think Different. Like The Rest Of Us."

iBook G4/1.2GHz | 1.25GB | 60GB | Mac OS X 10.4.2
Athlon XP 2500+/1.83GHz | 1GB PC3200 | 120GB | Windows XP
     
Mac Elite
Join Date: Feb 2002
Location: Hilton Head, SC
Status: Offline
Reply With Quote
Jul 25, 2003, 12:35 AM
 
Originally posted by macmike42:
grep doesn't search for file names, it searches the contents of files.
What do you mean the contents of files? Can you give an example? Perhaps display a command and the subsequent output? Thanks!
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Jul 25, 2003, 02:15 AM
 
Originally posted by Tyler McAdams:
What do you mean the contents of files? Can you give an example? Perhaps display a command and the subsequent output? Thanks!
man grep
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
Mac Elite
Join Date: Feb 2002
Location: Hilton Head, SC
Status: Offline
Reply With Quote
Jul 25, 2003, 05:02 AM
 
Originally posted by philzilla:
man grep
I'm currently at work on my windows box, I can't man grep...
     
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Jul 25, 2003, 09:14 AM
 
Originally posted by Tyler McAdams:
I'm currently at work on my windows box, I can't man grep...
Use this to find information online

Something I found...
     
Forum Regular
Join Date: Feb 2000
Status: Offline
Reply With Quote
Jul 25, 2003, 10:41 AM
 
... actually:
grep <options> pattern file
would be more accurate.

in any event you may also be interested in the r switch, which will recursively traverse directories:

grep -ri finder *

BTW: * tells grep to match ANY file, you could also replace it with something like:

grep -ri foo*

which would only match files whose names started with the 3 letters f, o, and o or exactly matched foo.

But as the prior reply mentioned time to do a little work on your own, as the web is literally littered with good file globbing, regular expression, etc tutorials which pretty much apply to ANY version of UNIX or UNIXlike OSes. That being said regular expressions are really not all that trivial and can take years to figure the entirety of the power, however much of it is fairly esoteric and usage/experience based/theoretical knowledge based. i.e. its much easier to understand if you have some knowledge of the theory of grammars in the computer science context.
     
Mac Elite
Join Date: Feb 2002
Location: Hilton Head, SC
Status: Offline
Reply With Quote
Jul 28, 2003, 08:08 PM
 
Originally posted by cutterjohn:
... actually:
grep <options> pattern file
would be more accurate.

in any event you may also be interested in the r switch, which will recursively traverse directories:

grep -ri finder *

BTW: * tells grep to match ANY file, you could also replace it with something like:

grep -ri foo*

which would only match files whose names started with the 3 letters f, o, and o or exactly matched foo.

But as the prior reply mentioned time to do a little work on your own, as the web is literally littered with good file globbing, regular expression, etc tutorials which pretty much apply to ANY version of UNIX or UNIXlike OSes. That being said regular expressions are really not all that trivial and can take years to figure the entirety of the power, however much of it is fairly esoteric and usage/experience based/theoretical knowledge based. i.e. its much easier to understand if you have some knowledge of the theory of grammars in the computer science context.

So it's: grep thetextiwant thefileiwanttosearchin
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 08:22 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2