[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible bug with parameter -m
From: |
Stefan Sassenberg |
Subject: |
Re: Possible bug with parameter -m |
Date: |
Tue, 26 Jun 2007 14:33:49 +0200 |
User-agent: |
Thunderbird 2.0.0.0 (X11/20070326) |
Benno wrote:
> Stefan Sassenberg wrote:
> > I have a file named "file" containing three lines
> > line1
> > line2
> > line3
> >
> > When I execute the following line in my bash
> > "while true; do grep ^ -m 1 ; done <file"
> > I expect the output
> > line1
> > line2
> > line3
> >
> > after three loop runs, one for every line found in the file.
>
> That would indeed be the correct output. From the man page: "If
> [...] NUM matching lines are output, grep ensures that the
> standard input is positioned to just after the last matching line
> before exiting [...]. This enables a calling process to resume a
> search." The endless repetition of line2 in your example is a bug
> in grep.
>
> It gets weirder when the lines have different lengths:
>
> $ cat file
> line1
> xxxx
> zz
> $ while true; do grep ^ -m1 ; done <file
> line1
> xxxx
>
> ine1
>
> ine1
> [...]
>
> $ cat file
> line1
> xxx
> zz
> $ while true; do grep ^ -m1 ; done <file
> line1
> xxx
> 1
> ne1
> 1
> ne1
> [...]
>
> $ cat file
> line1
> xx
> zz
> $ while true; do grep ^ -m1 ; done <file
> line1
> xx
> e1
> e1
> e1
> e1
> [...]
>
> > I'm not sure what happened, but recently that doesn't work
> > anymore.
>
> It did work in the past? With what version was that?
Hello Benno,
sorry that I didn't answer earlier. At the time I wrote my report I
wasn't in the list, and didn't get your answer. Now I am and we can go
on with the thread. This case is becoming urgent for me.
It has worked always for me before. I used that behaviour in a script
for years. Unfortunately I only call this script about once in two
months. I tried to find if I had a change in the grep version in the
near past, but I didn't find it out. That's the reason why I wrote
"possible" bug.
Are you a grep developer?
Stefan