Olivier Pons
Olivier Pons

Reputation: 15778

linux shell: why zero ending line dont work as expected?

I've read the "man" about grep, and when I try the "classical" way it works, whereas when I try using zero-ending lines, it doesn't work:

/cygdrive/g/eb # find . -type f | grep -E 'pdf$'
./Je_vais_mieux.pdf
./La_delicatesse.pdf
./Femme.pdf
./Souvenirs.pdf
/cygdrive/g/eb # find . -type f -print0 | grep -ZE 'pdf$'
Binary file (standard input) matches
/cygdrive/g/eb # find . -type f -print0 | grep -zE 'pdf$'
Binary file (standard input) matches
/cygdrive/g/eb # find . -type f -print0 | grep -ZzE 'pdf$'
Binary file (standard input) matches

What am I missing?

Upvotes: 0

Views: 33

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295472

You're missing grep -a, to tell grep that its input is in fact textual in nature:

find . -type f -print0 | grep -E -Zz -a 'pdf$'

That said, this is a silly thing to do, as find can filter its own output by suffix without help from grep:

find . -name '*pdf' -type f -print0

Upvotes: 1

Related Questions