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? Benno
