|
Home > Archive > Unix Shell > May 2004 > how to search files by pattern?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to search files by pattern?
|
|
| dmitry_kulinich 2004-05-31, 6:06 pm |
| Please if possible correct me, I'm beginner only:
grep -f patternfile / #I need all file system# | find / -type file -exec[vbcol=seagreen]
One more problem how to put in the listoffiles only the names of files in
which was found pattern lines?
| |
| Charles Harrison Caudill 2004-05-31, 6:06 pm |
| dmitry_kulinich <dkul@isd.dp.ua> wrote:
> Please if possible correct me, I'm beginner only:
> grep -f patternfile / #I need all file system# | find / -type file -exec
I'm not quite sure what you're asking
It looks like you want to grep in all the files on the system
grep -r will search recursively
find -type exepcts a letter not a word ie, for finding all regular files, it
would be find -type f
why are you piping output to find?
[vbcol=seagreen]
> One more problem how to put in the listoffiles only the names of files in
> which was found pattern lines?
find / -regex "<insert pattern here>" -type f > my_list_of_files_matching
HTH
--
Harrison Caudill | .^ www.hypersphere.org
Computer Science & Physics Double Major | | Me*Me=1
Georgia Institute of Technology | v' I'm just a normal guy
| |
| Barry Margolin 2004-05-31, 6:06 pm |
| In article <c97f6g$psl$1@mfdebug.isd.dp.ua>,
"dmitry_kulinich" <dkul@isd.dp.ua> wrote:
> Please if possible correct me, I'm beginner only:
> grep -f patternfile / #I need all file system# | find / -type file -exec
> One more problem how to put in the listoffiles only the names of files in
> which was found pattern lines?
I realize that English may not be your native language, so I'm trying
really hard to understand your questions, but I'm having a really hard
time. Please try to explain what you're trying to do better.
I think what you want may be:
find / -type f -print | xargs grep -l -f patternfile > listoffiles
The -l option to grep makes it just print out the names of the files
that matched.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| dmitry_kulinich 2004-05-31, 6:07 pm |
| >find / -regex "<insert pattern here>" -type f > my_list_of_files_matching
Great!...but if a pattern have 10 lines?
"Charles Harrison Caudill" <kungfoo@myrna.cc.gatech.edu> wrote in message
news:c97lhs$60o$1@solaria.cc.gatech.edu...
> dmitry_kulinich <dkul@isd.dp.ua> wrote:
file -exec[vbcol=seagreen]
>
> I'm not quite sure what you're asking
>
> It looks like you want to grep in all the files on the system
> grep -r will search recursively
>
> find -type exepcts a letter not a word ie, for finding all regular files,
it
> would be find -type f
>
> why are you piping output to find?
>
>
in[vbcol=seagreen]
>
> find / -regex "<insert pattern here>" -type f > my_list_of_files_matching
>
> HTH
>
> --
> Harrison Caudill | .^ www.hypersphere.org
> Computer Science & Physics Double Major | | Me*Me=1
> Georgia Institute of Technology | v' I'm just a normal guy
| |
| dmitry_kulinich 2004-05-31, 6:07 pm |
| find / -type f -print | xargs grep -l -f patternfile > listoffiles
Thats great but it takes different lines from the pattren and searching it.
But I don't need line by line search-all content of patternfile is 1 pattren
only.
"Barry Margolin" <barmar@alum.mit.edu> wrote in message
news:barmar-12A6B2.11454128052004@comcast.dca.giganews.com...
> In article <c97f6g$psl$1@mfdebug.isd.dp.ua>,
> "dmitry_kulinich" <dkul@isd.dp.ua> wrote:
>
file -exec[vbcol=seagreen]
in[vbcol=seagreen]
>
> I realize that English may not be your native language, so I'm trying
> really hard to understand your questions, but I'm having a really hard
> time. Please try to explain what you're trying to do better.
>
> I think what you want may be:
>
> find / -type f -print | xargs grep -l -f patternfile > listoffiles
>
> The -l option to grep makes it just print out the names of the files
> that matched.
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
| |
| Ed Morton 2004-05-31, 6:07 pm |
|
dmitry_kulinich wrote:
> find / -type f -print | xargs grep -l -f patternfile > listoffiles
> Thats great but it takes different lines from the pattren and searching it.
> But I don't need line by line search-all content of patternfile is 1 pattren
> only.
Many people have posted various solutions attempting to help you based
on the various way's you've phrased your questions, but I don't believe
any of us really understands what it is you want. You NEED to post some
sample input and output to get the right answer.
Ed.
| |
| Barry Margolin 2004-05-31, 6:07 pm |
| In article <c97uct$iqq$1@mfdebug.isd.dp.ua>,
"dmitry_kulinich" <dkul@isd.dp.ua> wrote:
> Great!...but if a pattern have 10 lines?
Grep works a line at a time, printing each line that matches the
pattern. A pattern that contains multiple lines will never match
anything.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Alan Connor 2004-05-31, 6:07 pm |
| On Fri, 28 May 2004 20:54:36 +0300, dmitry_kulinich <dkul@isd.dp.ua> wrote:
>
[ please bottom-post and trim your posts ]
>
> 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
|
|
|
|
|