Re: [newbie] grep search

2002-07-28 Thread Moshe Kaminsky

Hi,

You may use the find command. find allows you to go through a directory
tree and perform some tests and actions on it. For example, in your case
you want something like

  find / -path /mnt -prune -o -type f -exec grep my exp {} \;

Here, the / means start in /, the '-path /mnt -prune' means if the path
is of the form /mnt, don't go into it, the '-o' is a logical or, '-type f'
means only regular files, and the -exec says what command to execute
(the '{}' is replaced by the file name). find has many other option, all
of which you can read about in man find. Note in particular the -mount
option, which might be a simpler way to do what you want

HTH
Moshe

* Anne Wilson [EMAIL PROTECTED] [020724 20:59]:
 Is there a way of using grep to search for a word in all directories except 
 those under /mnt ?
 
 Anne
 

 Want to buy your Pack or Services from MandrakeSoft? 
 Go to http://www.mandrakestore.com




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



[newbie] grep search

2002-07-24 Thread Anne Wilson

Is there a way of using grep to search for a word in all directories except 
those under /mnt ?

Anne



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] grep search

2002-07-24 Thread civileme

Anne Wilson wrote:

Is there a way of using grep to search for a word in all directories except 
those under /mnt ?

Anne




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Well you don't want to search /proc either

The easy way is probably to use a list that you develop with ls and sed

ls -I 'mnt' -I 'proc' -R -1 -d / | grep '/?|(yoursearchstring)'

should generate the list of files matching your search with each match 
headed by its enclosing directories.  That is is you are looking for a 
match in the file name.

Now if you are looking for a match in the file contents, it is a little 
trickier,,,

grep -i -l --exclude 'mnt|proc' -e (yourpatternwithoutquotes) /

The -i is for ignore case and the -l lists only the file, not the 
matching lines within it.  The --exclude implies recursive (-r or -d 
recurse).

Civileme






Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] Grep..?

2002-07-03 Thread Moshe Kaminsky

In fact, you probably want *only* the name of the file, for which you
can use
  grep -l ...

Moshe

* Jan Wilson [EMAIL PROTECTED] [020701 18:49]:
 * Damian G [EMAIL PROTECTED] [020701 08:46]:
  the command looks like this:
  
  grep -i -A 2  ~/CDs/* -e searchterm
  
  will look inside of every file in ~/CDs/ directory, the  -i  switch
  means 'ignore the difference between upper and lowercase' so it can
  find Gaim when i search for gaim , then 
  -A 2 means i want it to show me two lines After the matching  line.
  and  -e searchterm is... well, the search term.
 
 You might try the -H option to grep.  It produces output like this,
 which might be a cleaner output:
 
 $ grep -H 'Senator' *.qif
 cash.qif:PSenator Inn
 cp91.qif:PThe Senator Inn  Conf Ctr
 cp92.qif:PSenator Inn  Conference Center
 cp.qif:PThe Senator Inn  Conf Ctr
 cp.qif:PSenator Inn
 cp.qif:ASenator Inn  Conference Cente
 
 
 -- 
 Jan Wilson, SysAdmin _/*];  [EMAIL PROTECTED]
 Corozal Junior College   |  |:'  corozal.com corozal.bz
 Corozal Town, Belize |  /'  chetumal.com  linux.bz
 Reg. Linux user #151611  |_/   Network, SQL, Perl, HTML
 
 

 Want to buy your Pack or Services from MandrakeSoft? 
 Go to http://www.mandrakestore.com




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] Grep..?

2002-07-01 Thread Anne Wilson

On Monday 01 Jul 2002 2:42 am, you wrote:
 On Sun, 30 Jun 2002 22:35:02 -0300

 Damian G [EMAIL PROTECTED] wrote:
  hi listers ...
 
  maybe my brains are working slower than usual as i think the winter
  caught up on me and i'm feeling kinda... dead.
 
  anyway, here's my problem:
 
  i've read the man page for Grep and i really can't figure out
  wether what i want to do is possible or not.
 
  i have a lot of backup  CD's and everytime i needed to restore
  something i had to look for it in avery single one of them, as
  maintaining a list of all of their contents would be a job demanding
  more time and patience than i have.
 
  so, basically i started inserting every backup CD i had and doing
 
  ls -R /mnt/cdrom  /home/user/cds/cd**.txt
 
  where the ** is a number.
 
  this way i got a pretty raw list of the contents of each CD.
  now, i need grep to tell me inside of which file the search
  criteria is found. for example i run this:
 
  cat /home/user/cds/* | grep -10 gaim
 
  it shows me the Gaim rpm file, 10 lines above, and 10 lines below.
  that's fine but now i need to know inside of which file it found that!
 
  is that possible?
 
  thanks.
 
  Damian

 never mind... figured it out myself. first attempt AFTER i made the
 post.

 some days you are better off not stepping out of your bed.

 sorry.

 Damian

But posting the solution might help others :-)

Anne



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] Grep..?

2002-07-01 Thread Damian G

 
  never mind... figured it out myself. first attempt AFTER i made the
  post.
 
  some days you are better off not stepping out of your bed.
 
  sorry.
 
  Damian
 
 But posting the solution might help others :-)
 
 Anne
 

ok, ;o)

the command looks like this:

grep -i -A 2  ~/CDs/* -e searchterm

will look inside of every file in ~/CDs/ directory, the  -i  switch
means 'ignore the difference between upper and lowercase' so it can
find Gaim when i search for gaim , then 
-A 2 means i want it to show me two lines After the matching  line.
and  -e searchterm is... well, the search term.

this one reports findings like this, for example: 

[user@localhost user]$grep -i -A 2  ~/CDs/* -e kylix

/home/user/CDs/installers 7-kylix shit/
/home/user/CDs/installers 7-DATA.Z*
/home/user/CDs/installers 7-_INST32I*

where installers 7 is the file in which kylix was found ( in this 
case means the title of the CD), and the rest of the lines are files
and subdirectories...

of course i made an alias for this on my .bashrc so i don't have to
remember this stuff..  ;oP

Damian



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] Grep..?

2002-07-01 Thread Jan Wilson

* Damian G [EMAIL PROTECTED] [020701 08:46]:
 the command looks like this:
 
 grep -i -A 2  ~/CDs/* -e searchterm
 
 will look inside of every file in ~/CDs/ directory, the  -i  switch
 means 'ignore the difference between upper and lowercase' so it can
 find Gaim when i search for gaim , then 
 -A 2 means i want it to show me two lines After the matching  line.
 and  -e searchterm is... well, the search term.

You might try the -H option to grep.  It produces output like this,
which might be a cleaner output:

$ grep -H 'Senator' *.qif
cash.qif:PSenator Inn
cp91.qif:PThe Senator Inn  Conf Ctr
cp92.qif:PSenator Inn  Conference Center
cp.qif:PThe Senator Inn  Conf Ctr
cp.qif:PSenator Inn
cp.qif:ASenator Inn  Conference Cente


-- 
Jan Wilson, SysAdmin _/*];  [EMAIL PROTECTED]
Corozal Junior College   |  |:'  corozal.com corozal.bz
Corozal Town, Belize |  /'  chetumal.com  linux.bz
Reg. Linux user #151611  |_/   Network, SQL, Perl, HTML




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



[newbie] Grep..?

2002-06-30 Thread Damian G


hi listers ... 

maybe my brains are working slower than usual as i think the winter 
caught up on me and i'm feeling kinda... dead.

anyway, here's my problem:

i've read the man page for Grep and i really can't figure out
wether what i want to do is possible or not.

i have a lot of backup  CD's and everytime i needed to restore 
something i had to look for it in avery single one of them, as
maintaining a list of all of their contents would be a job demanding
more time and patience than i have.

so, basically i started inserting every backup CD i had and doing

ls -R /mnt/cdrom  /home/user/cds/cd**.txt

where the ** is a number. 

this way i got a pretty raw list of the contents of each CD.
now, i need grep to tell me inside of which file the search
criteria is found. for example i run this:

cat /home/user/cds/* | grep -10 gaim

it shows me the Gaim rpm file, 10 lines above, and 10 lines below.
that's fine but now i need to know inside of which file it found that!

is that possible?

thanks.

Damian





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] Grep..?

2002-06-30 Thread Damian G

On Sun, 30 Jun 2002 22:35:02 -0300
Damian G [EMAIL PROTECTED] wrote:

 
 hi listers ... 
 
 maybe my brains are working slower than usual as i think the winter 
 caught up on me and i'm feeling kinda... dead.
 
 anyway, here's my problem:
 
 i've read the man page for Grep and i really can't figure out
 wether what i want to do is possible or not.
 
 i have a lot of backup  CD's and everytime i needed to restore 
 something i had to look for it in avery single one of them, as
 maintaining a list of all of their contents would be a job demanding
 more time and patience than i have.
 
 so, basically i started inserting every backup CD i had and doing
 
 ls -R /mnt/cdrom  /home/user/cds/cd**.txt
 
 where the ** is a number. 
 
 this way i got a pretty raw list of the contents of each CD.
 now, i need grep to tell me inside of which file the search
 criteria is found. for example i run this:
 
 cat /home/user/cds/* | grep -10 gaim
 
 it shows me the Gaim rpm file, 10 lines above, and 10 lines below.
 that's fine but now i need to know inside of which file it found that!
 
 is that possible?
 
 thanks.
 
 Damian
 
 
 

never mind... figured it out myself. first attempt AFTER i made the
post.

some days you are better off not stepping out of your bed.

sorry.

Damian

 



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] grep -r *.c doesn't find files

2001-08-24 Thread Jan Wilson

* George Petri [EMAIL PROTECTED] [010824 21:11]:
 I notice that grep -r *.c doesn't recurse through all folders (unless, of 
 course, they're called something.c).
 
 How do I tell grep to recurse through ALL subfolders and find .c files?

grep -r *.c should recurse through directories to find the pattern
*.c in ... well, nothing.  You gave it no files to
look for, so it is waiting for standard input.

With the subject you gave, you probably want find instead of grep.
Whichever you want, try

man grepor
man find

-- 
Jan Wilson, SysAdmin _/*];  [EMAIL PROTECTED]
Corozal Junior College   |  |:'  corozal.com corozal.bz
Corozal Town, Belize |  /'  chetumal.com  linux.bz
Reg. Linux user #151611  |_/   Network, SQL, Perl, HTML




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://.mandrakestore.com



Re: [newbie] grep -r *.c doesn't find files

2001-08-12 Thread David E.Fox

On Sunday 12 August 2001 06:44 am, George Petri wrote:

 Surely, grep can do something this basic, can't it
 (didn't the author of grep write c programs too:)?
 I don't like find and its complexity very much.

Recall that the tools in Unix are (or at least were at one point) designed to 
do one thing well, and do it simply. If there is a command that will return a 
list of files, there really isn't a need for that functionality to be put 
into another command that does something else. 

Unfortunately, find can be difficult to learn to use and it does have a lot 
of options. I tend to prefer something like :

# grep whatever `find . -name *.c`

By using the backquotes, that simply  substitutes the filenames that find 
returns right into the grep command line. But that can be impractical as find 
could return a great deal of filenames (thus a very long command line). But 
it's easier to type :).

It does turn out that the xargs solution is likely less stressful on the 
system. 

Grep actually can recurse - by using the -r switch on grep, it'll go through 
all files in a directory and directories within the parent directory (or 
matching filenames).

 55 days?  That's 2 months!  My X seems to die under heavy loads
 -- under that load average of 51.29 on a single Pentium II, X didn'

yeah, but I usually don't run the load average quite that high :). I don't 
think it's necessarily a case of the X server dying, but maybe the system is 
so stressed out that it's hard for it to respond to keystrokes or anything 
else. Recently I've noted a few tiimes where this has happened to me - 
sometimes by killing the X server and getting out of KDE I can reclaim the 
system. So far, I haven't had to reboot -- not in the last two months or so 
:).

 George

-- 

David E. Fox  Thanks for letting me
[EMAIL PROTECTED]change magnetic patterns
[EMAIL PROTECTED]   on your hard disk.
---




Re: [newbie] GREP

1999-10-23 Thread Ernest N. Wilcox Jr.

The grep command is a search tool for the command line. You can use it to fild
specific strings in selected files etc. To learn about grep use the man command
as in "man grep" (without the quotes). The man pages are a little criptic, but
with a little practice and carefull reading, you can find a lot of information
there.

Ernie


On Fri, 22 Oct 1999,Shannon M. Johnston wrote:
  | Does anybody know what the grep command do?



Re: [newbie] GREP

1999-10-22 Thread BryanMoorehead



I usually use grep to search either files or command output for string
ocurrences.

Ex.

grep "bryanm" user.txt  result

would return the contents of any line that contained bryanm in a file called
user.txt and dump the results to a file called result
leave  result off to dump to screen


You can do many things with it.

The man page, IMOHO, is all lecture with little practical application.

The best source I have found on most *nix commands is Unix Unleashed.

Hope this bit of rambling points you in the right direction.

Bryan








"Shannon M. Johnston" [EMAIL PROTECTED] on 10/22/99 12:04:30 PM

Please respond to [EMAIL PROTECTED]

To:   [EMAIL PROTECTED]
cc:(bcc: Bryan Moorehead/Link/Allied Holdings)
Subject:  [newbie] GREP




Does anybody know what the grep command do?









Re: [newbie] GREP

1999-10-22 Thread Ribbo

On Fri, Oct 22, 1999 at 10:04:30AM -0600, Shannon M. Johnston said:
 Does anybody know what the grep command do?
 

$ man grep
...
DESCRIPTION
Grep  searches the named input files (or standard input if
no files are named, or the file name - is given) for lines
containing a match to the given pattern.  By default, grep
prints the matching lines.



-- 
Rib



Re: [newbie] GREP

1999-10-22 Thread John Aldrich

On Fri, 22 Oct 1999, you wrote:
 Does anybody know what the grep command do?
Searches, essentially. For example, type the following at a
command prompt:
rpm -qa | grep sendmail

that will show you all the packages you have installed
which have "sendmail" as part of their name. Or you can try
"cat somefilename | grep something" and that will
search a specific file (typically a log file) for all
occurrances of whatever you're requesting and print 'em all
out for you on the screen. It's a very handy utility. :-)
John



Re: [newbie] GREP

1999-10-22 Thread John Aldrich

On Fri, 22 Oct 1999, you wrote:
 Does anybody know what the grep command do?

For more detail type "man grep" (minus quotes) at the
command prompt. :-)
John



Re: [newbie] GREP

1999-10-22 Thread Michael R. Batchelor



On Fri, 22 Oct 1999, Shannon M. Johnston wrote:

 Does anybody know what the grep command do?


grep = Global Regular Expression Processor

$ grep dog filename

will spew out every line in filename which contains
the string "dog"

Read through the docs for grep and egrep, then get
the O'Rielly book. Understanding this stuff will
be the most useful thing you'll ever learn about
Linux/Unix. (I've been doing this since '87, and
I've learned a lot of useful and useless stuff.)

MB



Re: [newbie] grep and replace

1999-09-03 Thread Matt Stegman

Maybe this would do it (as a shell script):

#! /bin/sh
for $i in `find .`; do
cp $i $i.old
cat $i.old | sed -e "s/MarketingWorks\/Collard
Associates/MarketingWorks"  $i
next;

I am NOT a shell script guru- you can tell because my for loop syntax is
wrong, and I'm not sure what the proper way to write it is.  I hope I
get my idea across, though.  You might run it as `script 2 /dev/null`
because it will generate an error message for every directory under ./
as I couldn't figure out a way to get `find` to list only files, or 
`ls -R` to not print out directory names.  
With this pseudo-script, you also get backups of your HTML files
(with a .old extension) in case it screws up.  If it works, then you can 
rm `find . |grep .old`
to recusively remove all old files.  I think.

-Matt Stegman
[EMAIL PROTECTED]

On Thu, 2 Sep 1999, James Stewart wrote:

 Been investigating the problem I posted yesterday a bit more, and have a
 slightly better way of expressing it now ;)
 
 What I want to do is like issuing:
 
 grep -r MarketingWorks\/Collard Associates /home/httpd/marketingworks.co.uk
 
 but instead of listing the results I want to replace it with simply
 MarketingWorks
 
 Another way of looking at it is issuing perl's
 s/MarketingWorks\/Collard Associates/MarketingWorks/;
 
 but recursively through the directory structure.
 
 Can anyone suggest how to do this?
 
 James.
 -- 
 James Stewart |  Britlinks |  The Phantom Tollbooth
 [EMAIL PROTECTED] | http://www.britlinks.co.uk | http://www.tollbooth.org
 
  Sixpence None The Richer UK -- http://www.britlinks.co.uk/sixpence/
 




[newbie] grep and replace

1999-09-02 Thread James Stewart

Been investigating the problem I posted yesterday a bit more, and have a
slightly better way of expressing it now ;)

What I want to do is like issuing:

grep -r MarketingWorks\/Collard Associates /home/httpd/marketingworks.co.uk

but instead of listing the results I want to replace it with simply
MarketingWorks

Another way of looking at it is issuing perl's
s/MarketingWorks\/Collard Associates/MarketingWorks/;

but recursively through the directory structure.

Can anyone suggest how to do this?

James.
-- 
James Stewart |  Britlinks |  The Phantom Tollbooth
[EMAIL PROTECTED] | http://www.britlinks.co.uk | http://www.tollbooth.org

 Sixpence None The Richer UK -- http://www.britlinks.co.uk/sixpence/