Zsh glob to exclude binary files

I am looking for files containing the string "abc" in the current directory and in all subdirectories:

grep abc **/*(.)

The output contains lines such as:

...
Binary file test.pdf matches
...

Is it possible to exclude binaries in the glob qualifier?

EDIT : The use grephere is just an example. I am interested in excluding binaries using glshing zsh specifiers, and not in the corresponding grep options.

+4
source share
2 answers

The message "Binary file test.pdf matches" is not printed by zsh, but by grep itself.

, , , , "" (.. , ..).

**/* (.) zsh. , echo:

$ echo **/*(.)

, **/* (.) .

$ mkdir test
$ cd test
$ touch .mytest
$ echo  **/*(.)
zsh: no matches found: **/*(.)

, , , :

$ grep -rI .

, :

$ grep -r *

zsh globbing . zshexpn (1):

A qualifier may be any one of the following:

   /      directories
   F      `full'  (i.e.  non-empty)  directories.  
   .      plain files
   @      symbolic links
   =      sockets
   (...)

, " ", " ". .

AFAIK, zsh glob , .

Zsh , .

- , zsh , , globbing (, , "" , IMO).

, ( , ).

grep, .

+5

glob. estring +cmd zshexpn(1).

- :

ls **/*(.e:'file --mime $REPLY | grep -iqv binary':)

:

notbinary() { file --mime $REPLY | grep -iqv binary }
ls **/*(.+notbinary)
+2

Source: https://habr.com/ru/post/1538857/


All Articles