[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
grep-2.5.1: bugs with "--only-matching"
From: |
Julian Foad |
Subject: |
grep-2.5.1: bugs with "--only-matching" |
Date: |
Thu, 14 Aug 2003 12:19:44 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 |
grep 2.5.1: bugs with "--only-matching" ("-o"):
1. For a case-insensitive match (with "-i"), when the case does not in fact match,
"-o" displays empty text, and not even a newline after it (so also messes up the output
of line numbers or file names).
2. It only displays the line number (-n) or file name (-H) for the first match on a line.
The output of subsequent matches is at least inconvenient for further processing (with
"sort" etc.) and can also be ambiguous because anything that looks like a
requested line number or file name might instead be part of the matched text.
3. The end of a previous match is mistaken for the start of a new line, matching
"^".
Reproduction script, showing the output with and without "-o":
[[[
#!/bin/bash
# Demonstrate bugs in "-o" ("--only-matching") option of GNU Grep 2.5.1
grep --version | head -1
TEXT="word
WORD
WORD_WORD
"
set -v
# Bug: Displays empty text, and no newline, for a match that requires "-i".
# Bug: Only displays the line (-n) or file name (-H) for the first match on a
line.
echo "$TEXT" | grep -ni WORD
echo "$TEXT" | grep -nio WORD
# Bug: End of a previous match is mistaken for the start of a new line.
echo "$TEXT" | grep -n "^WORD_*"
echo "$TEXT" | grep -no "^WORD_*"
]]]
This is the output that I get from that script:
[[[
grep (GNU grep) 2.5.1
# Bug: Displays empty text, and no newline, for a match that requires "-i".
# Bug: Only displays the line (-n) or file name (-H) for the first match on a
line.
echo "$TEXT" | grep -ni WORD
1:word
2:WORD
3:WORD_WORD
echo "$TEXT" | grep -nio WORD
1:2:WORD
3:WORD
WORD
# Bug: End of a previous match is mistaken for the start of a new line.
echo "$TEXT" | grep -n "^WORD_*"
2:WORD
3:WORD_WORD
echo "$TEXT" | grep -no "^WORD_*"
2:WORD
3:WORD_
WORD
]]]
This is the output that I expect:
[[[
grep (GNU grep) 2.5.1
# Bug: Displays empty text, and no newline, for a match that requires "-i".
# Bug: Only displays the line (-n) or file name (-H) for the first match on a
line.
echo "$TEXT" | grep -ni WORD
1:word
2:WORD
3:WORD_WORD
echo "$TEXT" | grep -nio WORD
1:word
2:WORD
3:WORD
3:WORD
# Bug: End of a previous match is mistaken for the start of a new line.
echo "$TEXT" | grep -n "^WORD_*"
2:WORD
3:WORD_WORD
echo "$TEXT" | grep -no "^WORD_*"
2:WORD
3:WORD_
]]]
- Julian
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- grep-2.5.1: bugs with "--only-matching",
Julian Foad <=