bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#16965: Likely bug in grep for file without an ending newline


From: Jim Meyering
Subject: bug#16965: Likely bug in grep for file without an ending newline
Date: Fri, 7 Mar 2014 16:51:35 -0800

On Fri, Mar 7, 2014 at 2:38 PM, Abramo Bagnara <address@hidden> wrote:
>
> $ echo -n test > file
> $ fgrep e file
> test
> $ fgrep -v q file
> test
> $ cat file
> test$
>
> My expectation would be that file is not altered by grep if all lines
> matches pattern.

Thank you for the report.
Grep is specified to operate on so-called "lines" which are defined
to end with a newline, so the moment you give grep an input that
does not consist of lines, you're in "unspecified" territory.  I.e., what
grep does with that input is unspecified by POSIX. We have
chosen to make it append the newline in that case.

> Is current grep behavior the expected one?

It is documented in "info grep":

  If the final byte of an input file is not a newline, `grep' silently
supplies one.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]