Re: Find file that contains "....." (command in Unix)
by Abigail-II (Bishop) on Mar 28, 2003 at 08:15 UTC
|
find . -type f -print0 | xargs -0 grep -l
The advantage of using grep -l is that the
-l option makes grep print the file name of
the file that matches (instead of the matching line),
and grep will stop looking in the file after
the first match.
Abigail | [reply] [Watch: Dir/Any] [d/l] [select] |
|
Good solution, but you could run into trouble if the resulting command line is bigger than the maximum size supported by the OS.
If there are a lot of files to be checked, then it could be the case to check them one by one. So I'd slightly modify your command line this way:
find . -type f -exec grep -Hl {} \;
Update: grep here is the GNU grep
Ciao! --bronto
The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
Good solution, but you could run into trouble if the resulting command line is bigger than the maximum size
supported by the OS.
Of course, you will only run into trouble if your xargs
is broken. The point of using xargs is to avoid the
problem you are describing.
The disadvantage of using -exec is that find
will spawn a grep process for each file found, while
with the use of xargs, far less processes will be
spawned.
Abigail
| [reply] [Watch: Dir/Any] |
|
Re: Find file that contains "....." (command in Unix)
by Corion (Patriarch) on Mar 28, 2003 at 07:54 UTC
|
The module File::Find::Rule has a nice and easy interface to do this (as seen in the documentation) :
my @files = File::Find::Rule->grep( qr/^whatever is in the file$/ )
->in('test');
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The
$d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider
($c = $d->accept())->get_request(); $c->send_response( new #in the
HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: Find file that contains "....." (command in Unix)
by robartes (Priest) on Mar 28, 2003 at 07:50 UTC
|
find . -type f -exec grep "\.\.\.\.\." /dev/null {} \;
Or if you have a modernish grep:
grep -r "\.\.\.\.\." .
Update: The OP requested the file name, the solutions print all lines containin the pattern. This does what the OP wants:
find . -type f -exec grep -q "\.\.\.\.\." {} \; -exec echo 'Found {}'
+ \;
CU Robartes- | [reply] [Watch: Dir/Any] [d/l] [select] |
|
grep -F -r -I -l '.....' . | grep '.txt$'
...first part of the pipeline recursively, -r, (downword only) searches
text files, -I, for ..... in the current
directory, ., listing only the file names found.
Second part filters the file names which lists only those
ending in '.txt'.
Here is one more and bit more robust (to be run in "test" directory; see OP)...
find . -type f -name '*.txt' -print0 | xargs -0 grep -F -l '.....'
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
or just find . -type f -exec grep -lq "\.\.\.\.\." {} \;
-Waswas
| [reply] [Watch: Dir/Any] [d/l] |
Re: Find file that contains "....." (command in Unix)
by nite_man (Deacon) on Mar 28, 2003 at 08:05 UTC
|
grep -rE "\.{5}" `ls /my_folders`
-------->
SV* sv_bless(SV* sv, HV* stash);
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
Re: Find file that contains "....." (command in Unix)
by blakem (Monsignor) on Mar 28, 2003 at 10:02 UTC
|
None of the solutions posted so far are exactly what I would do... How about a simple:
grep -lr yourstring /path/to/your/dir
-Blake
| [reply] [Watch: Dir/Any] [d/l] |
|
The -r option on grep is not uniformely
supported. It's not in the POSIX standard.
The question was about a Unix command; and
GNU stands for "GNU is Not Unix". ;-)
Abigail
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] [d/l] |
|
|
|
|
| [reply] [Watch: Dir/Any] |
Re: Find file that contains "....." (command in Unix)
by Anonymous Monk on Jul 31, 2009 at 04:19 UTC
|
find some more information about unix find command at
http://scripterworld.blogspot.com/2009/07/unix-find-command-with-examples-and.html
| [reply] [Watch: Dir/Any] |