Subject: bug#33972: closed (grep -vf <(<nothing>) filters all rows)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 02 Jan 2020 09:05:02 +0000

Your bug report

#33972: grep -vf <(<nothing>) filters all rows

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
33972: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=33972
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: grep -vf <(<nothing>) filters all rows
From: Paul Eggert <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Thu, 2 Jan 2020 01:04:21 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

> I have to pre-check for an empty set before passing it to grep:
> ...
> Workaround:

You're right that the empty pattern matches every line, since every line has an
empty string in it somewhere. This is considered to be a feature of grep, not a
bug. As you have a workaround I'm closing the bug report.

Subject: grep -vf <(<nothing>) filters all rows
From: [email-masked]
To: [email-masked]
Date: Fri, 4 Jan 2019 00:04:28 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

I have to pre-check for an empty set before passing it to grep:
 
SAVED_RECORDs=($(sqlite3 -list -separator '/' files.db "SELECT FileName FROM Files WHERE ModTime > '2018-12-31'")) #Returns an empty set
NEW_RECs=($(ls * | grep -vf <(echo ${SAVED_RECORDs[@]}
| tr ' ' '\n') #Returns an empty list because grep considers SAVED_RECORDs to be universal rather than null set
Workaround:

if [ ${#SAVED_RECORDs[@]} -gt 0 ]; then

  NEW_RECs=($(ls * | grep -vf <(echo ${SAVED_RECORDs[@]} | tr ' ' '\n') #Now returns the expected subtraction of SAVED_RECORDs from NEW_RECs

fi