[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #21401] Newline inserted by grep at EOF causes false positives
From: |
anonymous |
Subject: |
[bug #21401] Newline inserted by grep at EOF causes false positives |
Date: |
Tue, 23 Oct 2007 13:57:26 +0000 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.8) Gecko/20071008 Firefox/2.0.0.8 |
URL:
<http://savannah.gnu.org/bugs/?21401>
Summary: Newline inserted by grep at EOF causes false
positives
Project: grep
Submitted by: None
Submitted on: Tuesday 10/23/2007 at 13:57 UTC
Category: None
Severity: 3 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
Discussion Lock: Any
_______________________________________________________
Details:
I have the following file:
Line 1\r\n
Line 2
The first line has a DOS newline, while the second has no newline at all.
For information, the hexdump of the file is:
00000000 4c 69 6e 65 20 31 0d 0a 4c 69 6e 65 20 32
0000000e
I want to know if the file contains Unix newlines (\n).
Therefore, I run grep on it in the following way:
$ grep -P '[^\x0d]\x0a' file.txt
Line 2
The problem is that grep thinks that Line 2 matches, which is definitely not
the case.
The following experience pinpoints the problem:
$ grep -P '[^\x0d]\x0a' file.txt | hexdump -C
00000000 4c 69 6e 65 20 32 0a
00000007
grep has apparently inserted a newline automatically at the end of the file,
using the Unix format, which then matches my regexp.
So grep should find not match in the file, and it finds one.
It's a corner case, but it's an bug, even an annoying bug if one is
troubleshooting newline issues.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?21401>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bug #21401] Newline inserted by grep at EOF causes false positives,
anonymous <=