When interpreting supplied pattern as perl regular expression grep displays match across multiple lines --- in spite of the ^beginning-of-line character specified in the pattern. Actual result: $ echo -e "\n\n\n foo" | grep -P '^\s*foo' foo Expected result: The leading empty lines should be omitted from the output: $ echo -e "\n\n\n foo" | grep -P '^\s*foo' foo
Unfortunately, the -P option of GNU grep is still only an experimental feature in the upstream source.