When I enter:
cat abc | grep -B 1 -i xyz > xyz
or
cat abc | grep --before-context=1 -i xyz > xyz
and xyz is found, the prior line will be output when entered via bash
but not when done within a script. It will sometimes output a prior
line, but rarely the immediately prior line, which it always does when
entered by Konsole.
The script file begins with "#!/bin/bash"
Results are the same when:
the output is redirected to a file or defaults to the terminal.
-i prior to search string is used or not.
assorted values for xyz
grep --help shows
-B, --before-context=NUM print NUM lines of leading context
This is in openSUSE 10.2 - 64 bit. and was also there with 10.0 - 32 bit
and 10.1 - 32 bit, accessing as a normal user via Konsole.
Thanks, John