[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help needed

From: Bernhard Voelker
Subject: Re: Help needed
Date: Tue, 8 Sep 2015 15:43:49 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

On 09/08/2015 01:18 PM, Carlos Lopes wrote:

I'm trying to use findutils to find files based on their name, but since
there are many patterns to search, I would like to know if it is possible to
pass a file with the patterns:

This works fine:

find w:\ -iname "*33*"

(it returns a list of files that have "33" on the name )

But I wanted to use a file instead of "*33*", is it possible?
For example, if I have a test.txt file with this data:


How could I pass the information so that the program searches all
information in the file with just one command?

GNU find doesn't have an option to read the patterns from a file,
and it would maybe be problematic to say if such patterns should
be treated like as for the -name, -iname, -regex etc. options.

Therefore, I'd go with a more practical approach e.g. based on

  find . | grep -f test.txt

But again, you need to know what the patterns should match.
E.g., if it should only match the basename of each hit, then
you should wrap the patterns in test.txt to match only the basename
like maybe:

  $ find . | grep -f <( sed 's#^#/[^/]*#; s#$#[^/]*#' test.txt)

If the number of patterns is not that big, then I'd maybe generate
the command line for 'find' like this:

  $ sed "s/^/-iname '*/; 2,$ s/^/-o /; s/$/*'/" test.txt | tr '\n' ' '
  -iname '*33*' -o -iname '*43435*' -o -iname '*343434*' -o -iname '*756565*'

Note: I'm working on a windows7 environment.

There exist several implementations of GNU find for Windows,
e.g. the one in Cygwin.  That in particular comes with a nice
shell which allows the same syntax as used in the examples

However, this is all out of scope of the upstream find project.

Have a nice day,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]