GNU bug report logs - #63962
possible error in the grep program

Previous Next

Package: grep;

Reported by: Василий Алексеенко <vasilisc777 <at> gmail.com>

Date: Thu, 8 Jun 2023 15:29:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 63962 in the body.
You can then email your comments to 63962 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#63962; Package grep. (Thu, 08 Jun 2023 15:29:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Василий Алексеенко <vasilisc777 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Thu, 08 Jun 2023 15:29:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Василий Алексеенко
 <vasilisc777 <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: possible error in the grep program
Date: Thu, 8 Jun 2023 14:27:49 +0300
[Message part 1 (text/plain, inline)]
Hello,

in my work, I encountered a possible error in the grep program.
$ grep -V
grep (GNU grep) 3.4

1) The initial list of IP addresses in the file is formed start_list.txt .

2) Must be removed from the list start_list.txt IP addresses using a
larger file exclude_list.txt

grep -vF --file=exclude_list.txt start_list.txt > list_grep.txt

3) But after a series of checks, it turned out that grep "loses" 3 IP addresses
10.0.23.48
10.0.27.40
10.0.38.43

4) A bash script was written that solves the same problem in a different way

#!/bin/bash

:> list_while.txt
while read l
do
    if ! grep -m 1 -q "$l" exclude_list.txt; then
        echo ${l} >> list_while.txt
    fi
done < start_list.txt

5) The diff program has confirmed that there is indeed a difference in
the results

$ diff list_grep.txt list_while.txt
22a23
> 10.0.23.48
24a26
> 10.0.27.40
28a31
> 10.0.38.43

-- 
Best regards,
Vasilisc
[bug_grep.tar.gz (application/x-gzip, attachment)]

Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Thu, 08 Jun 2023 21:08:02 GMT) Full text and rfc822 format available.

Notification sent to Василий Алексеенко <vasilisc777 <at> gmail.com>:
bug acknowledged by developer. (Thu, 08 Jun 2023 21:08:02 GMT) Full text and rfc822 format available.

Message #10 received at 63962-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Василий Алексеенко
 <vasilisc777 <at> gmail.com>
Cc: 63962-done <at> debbugs.gnu.org
Subject: Re: bug#63962: possible error in the grep program
Date: Thu, 8 Jun 2023 14:07:16 -0700
On 6/8/23 04:27, Василий Алексеенко wrote:

> 1) The initial list of IP addresses in the file is formed start_list.txt .
> 
> 2) Must be removed from the list start_list.txt IP addresses using a
> larger file exclude_list.txt
> 
> grep -vF --file=exclude_list.txt start_list.txt > list_grep.txt

The line '10.0.23.4' in exclude_list.txt matches the line '10.0.23.48' 
in start_list.text. That is, the first line is a substring of the second 
line. So this usage of 'grep' doesn't do what you want.

To get the effect you want, also use the -x option. E.g.:

grep -vxF -f exclude_list.txt start_list.txt




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 07 Jul 2023 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 287 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.