From unknown Mon Aug 18 09:02:04 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16965: Likely bug in grep for file without an ending newline Resent-From: Abramo Bagnara Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Fri, 07 Mar 2014 22:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 16965 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: jim@meyering.net, mark.veltzer@gmail.com, 16965@debbugs.gnu.org X-Debbugs-Original-To: jim@meyering.net, mark.veltzer@gmail.com, bug-grep@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.139423228126907 (code B ref -1); Fri, 07 Mar 2014 22:45:02 +0000 Received: (at submit) by debbugs.gnu.org; 7 Mar 2014 22:44:41 +0000 Received: from localhost ([127.0.0.1]:55315 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WM3VQ-0006zu-Oh for submit@debbugs.gnu.org; Fri, 07 Mar 2014 17:44:41 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52122) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WM3Pg-0006ot-BF for submit@debbugs.gnu.org; Fri, 07 Mar 2014 17:38:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WM3PX-00043d-Nu for submit@debbugs.gnu.org; Fri, 07 Mar 2014 17:38:44 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:52894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM3PX-00043E-LF for submit@debbugs.gnu.org; Fri, 07 Mar 2014 17:38:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM3PP-0008JC-5R for bug-grep@gnu.org; Fri, 07 Mar 2014 17:38:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WM3PG-0003wU-PR for bug-grep@gnu.org; Fri, 07 Mar 2014 17:38:27 -0500 Received: from mail-ee0-x233.google.com ([2a00:1450:4013:c00::233]:44896) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM3PG-0003wK-Fg for bug-grep@gnu.org; Fri, 07 Mar 2014 17:38:18 -0500 Received: by mail-ee0-f51.google.com with SMTP id c13so2010428eek.38 for ; Fri, 07 Mar 2014 14:38:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:organization:user-agent:mime-version:to :subject:content-type:content-transfer-encoding; bh=mr0q2YVI/6nU+d+F9y2TRPqrXMoBEWuuIVyYgfRtTj4=; b=Tbm+XULBX1h9+RlT94TEL+SL11sX1TNAOw+6vTZ7fp4bHyzptdaN30BHrEvKM0larK tVVFX+oKAKUIG+dUJKf8N32kqE/sEiOgHBdZEgGi7mzAHgejPu1eZQpNipg66j3njzxA g1pO+HSVYolNi6KclHhI38MEnv/wByz1Hy/eM9BtmITpfr+2jZJ3Y4SxL4rDKCEeBD9H uVkIhtsSMHh4O5uV2nWWExp1MZ0Ep2fZITc9efh4AcXopvmUrSxSGR7hqc0BbCoCONn7 EXnTwYL0kUT5feYpd4HJmkEfysDIU/l56a8Z28prVg8Wo+zEV5t2En1rg7RRD4fBXTt3 vVPw== X-Received: by 10.15.90.204 with SMTP id q52mr135485eez.95.1394231897075; Fri, 07 Mar 2014 14:38:17 -0800 (PST) Received: from [192.168.234.1] (host14-195-dynamic.16-87-r.retail.telecomitalia.it. [87.16.195.14]) by mx.google.com with ESMTPSA id m42sm11893226eex.21.2014.03.07.14.38.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Mar 2014 14:38:16 -0800 (PST) Message-ID: <531A4A54.10606@gmail.com> Date: Fri, 07 Mar 2014 23:38:12 +0100 From: Abramo Bagnara Organization: Opera Unica User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Mailman-Approved-At: Fri, 07 Mar 2014 17:44:36 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) $ 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. Is current grep behavior the expected one? -- Abramo Bagnara From unknown Mon Aug 18 09:02:04 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16965: Likely bug in grep for file without an ending newline Resent-From: Jim Meyering Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Sat, 08 Mar 2014 00:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16965 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Abramo Bagnara Cc: 16965@debbugs.gnu.org, mark.veltzer@gmail.com X-Debbugs-Original-Cc: bug-grep@gnu.org, mark.veltzer@gmail.com Received: via spool by submit@debbugs.gnu.org id=B.13942399239139 (code B ref -1); Sat, 08 Mar 2014 00:53:01 +0000 Received: (at submit) by debbugs.gnu.org; 8 Mar 2014 00:52:03 +0000 Received: from localhost ([127.0.0.1]:55378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WM5Ug-0002NL-Ld for submit@debbugs.gnu.org; Fri, 07 Mar 2014 19:52:02 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50303) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WM5Ue-0002Mu-BH for submit@debbugs.gnu.org; Fri, 07 Mar 2014 19:52:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WM5Ud-0004SP-KW for submit@debbugs.gnu.org; Fri, 07 Mar 2014 19:52:00 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:48298) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM5Ud-0004SL-Hi for submit@debbugs.gnu.org; Fri, 07 Mar 2014 19:51:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM5Uc-0003tb-NN for bug-grep@gnu.org; Fri, 07 Mar 2014 19:51:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WM5Ub-0004S3-MY for bug-grep@gnu.org; Fri, 07 Mar 2014 19:51:58 -0500 Received: from mail-pa0-x22d.google.com ([2607:f8b0:400e:c03::22d]:47889) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM5Ub-0004Ry-Fv for bug-grep@gnu.org; Fri, 07 Mar 2014 19:51:57 -0500 Received: by mail-pa0-f45.google.com with SMTP id kl14so4867814pab.4 for ; Fri, 07 Mar 2014 16:51:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=IFQlTeQgqrGrb+2f5rJedxfKkA/BFlKxho1v63deBCg=; b=x/wuCBcIjWJ+H14YColG3fdzNYS6iymClHGzsy3z6jvl0hx/K1EKWT3IKE9oH0yu5Y IBj2VWtkq31Hy1/cNfhs0Waqoug6vU0RHhncMxwngnK93Y0TMZT9ZtaM59xxco1h0b2p waT0ekIM8PvFvS0yaFAtGa4qXq88kgOkQiFJPIfyInuu7eI6OT5lHOShh+lmtXGQZjhh LdBqR8nalu5bSVxWrB4GSH7t1iO4GGewckXBdeFpkAChVrbL05L4Zypg9TMfFaQeQv+l vWYiNII59cDtW93gGuQiubrCasxHjSG5RX2rTDe4fEQAU1KkMn33vpAvw3f7JpWbAfqd d+vQ== X-Received: by 10.66.240.4 with SMTP id vw4mr25509164pac.26.1394239915968; Fri, 07 Mar 2014 16:51:55 -0800 (PST) MIME-Version: 1.0 Received: by 10.68.201.231 with HTTP; Fri, 7 Mar 2014 16:51:35 -0800 (PST) In-Reply-To: <531A4A54.10606@gmail.com> References: <531A4A54.10606@gmail.com> From: Jim Meyering Date: Fri, 7 Mar 2014 16:51:35 -0800 X-Google-Sender-Auth: 0N_3DgyNgLO-6ViL3jgrPtB3C_M Message-ID: Content-Type: text/plain; charset=ISO-8859-1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) On Fri, Mar 7, 2014 at 2:38 PM, Abramo Bagnara 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. From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 08 10:33:49 2014 Received: (at control) by debbugs.gnu.org; 8 Mar 2014 15:33:49 +0000 Received: from localhost ([127.0.0.1]:56696 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WMJG0-0004mf-Jw for submit@debbugs.gnu.org; Sat, 08 Mar 2014 10:33:48 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:34317) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WMJFy-0004mW-Lj for control@debbugs.gnu.org; Sat, 08 Mar 2014 10:33:47 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id DE7BF39E8013 for ; Sat, 8 Mar 2014 07:33:45 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E78kLmPc7wax for ; Sat, 8 Mar 2014 07:33:45 -0800 (PST) Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 93D2F39E8008 for ; Sat, 8 Mar 2014 07:33:45 -0800 (PST) Message-ID: <531B3853.6050909@cs.ucla.edu> Date: Sat, 08 Mar 2014 07:33:39 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: control@debbugs.gnu.org Subject: 16965 is not a bug Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) tags 16965 notabug close 16965 thanks