Re: how to search files by pattern?

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 05/29/04


Date: Sat, 29 May 2004 00:09:18 GMT

On Fri, 28 May 2004 20:54:36 +0300, dmitry_kulinich <dkul@isd.dp.ua> wrote:
>

  [ please bottom-post and trim your posts ]

>
>>find / -regex "<insert pattern here>" -type f > my_list_of_files_matching
> Great!...but if a pattern have 10 lines?

First of all, don't search your entire system. Only the directory trees that are
likely to have the file(s) you want. (not going to be in /proc or /dev or /lib,
right? Why search them?) My system locks up if I do grep -r 'search string' /
as root.

Find and grep -r both allow you to list the top directories of the trees you
want to search.

find /dir1 /dir2 /dir3...
grep -r 'search string' /dir1 /dir2 /dir3

One approach you could take would be to first locate the files that have ONE
of those lines:

(assuming bash and gnu grep)

$ grep -rl 'line 1............................................................\
...........' /dir1 /dir2 /dir3... > file1

This will give you a list of filenames that you can then feed to grep to look
for the next line (if you need to):

$ for file in $(cat file1); do ; \
grep -l 'line 2..........................................................\
.......' $file >> file2 ; done

And so forth....Though you can probably just use a short regular expression
to identify the lines. If you type them out literally, they will have to
be EXACT matches.

AC

-- 
Pass-List -----> Block-List ----> Challenge-Response
The key to taking control of your mailbox.  Design Parameters:
http://tinyurl.com/2t5kp ||   http://tinyurl.com/3c3ag
Challenge-Response links -- http://tinyurl.com/yrfjb


Relevant Pages

  • Re: Fraudulent eBay listing
    ... O.K. I had not noticed that you were using plain grep, ... in egrep), * simply stands for "zero or more of the preceding ... Interpret PATTERN as an extended regular expression. ...
    (rec.crafts.metalworking)
  • Re: grep
    ... > Grep understands two different versions of regular expression syntax: ... > will output any line that contains cat OR dog OR bird or any combination. ... > Does anyone know how to construct a regular expression or in any way get ... > bird dog cat ...
    (Fedora)
  • Re: tips for writing regular expression interpreter/compiler?
    ... The dfa and nfa programs perform conversions as above. ... is grep, souped up to handle general boolean combinations (A intersect ... just represent a regular expression as you would ... Denoting the normal form of an expression A by NF, ...
    (comp.compilers)
  • Re: [Q] Need help with grep expression
    ... post in to the correct news group - 'grep' is unix/linux shell scripting ... 'grep and replace' (linux command similar to 'sed')... ... then you'd need a regular expression and something like the ...
    (comp.lang.php)
  • Re: Text Editor
    ... > I was wondering if there is a text editor equivalent to TextPad for ... See the man pages for grep, egrep, fgrep. ... I tend to just use egrep and the simple regular expressions. ... " Grep understands two different versions of regular expression ...
    (Fedora)