[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [grep] strange behavior of `grep -o'
From: |
Eli Zaretskii |
Subject: |
Re: [grep] strange behavior of `grep -o' |
Date: |
Mon, 24 Oct 2005 11:34:11 +0200 |
> From: Alexandre Duret-Lutz <address@hidden>
> Date: Mon, 24 Oct 2005 07:45:20 +0200
>
> This looks unexpected to me:
>
> % echo 1234 | grep -o '^[0-9]'
> 1
> 2
> 3
> 4
> % grep --version
> grep (GNU grep) 2.5.1
>
> Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
>
> Because `-o' is documented as `show only the part of a line matching PATTERN',
> I would expect only `1' to be output.
Looking at the sources, it seems like this is the intended behavior,
and the documentation simply fails to describe it.
But I'm not the official Grep maintainer, so I cannot be sure whether
this is a bug or a feature.
If the current behavior is indeed intended, I think it should print
the line and/or buffer offset for each one of the multiple matches.
Right now, if you add the -n switch to your example, you get:
% echo 1234 | grep -no '^[0-9]'
1:1
2
3
4
instead of what I'd expect:
% echo 1234 | grep -no '^[0-9]'
1:1
1:2
1:3
1:4