From unknown Thu Jun 19 14:11:51 2025 X-Loop: help-debbugs@gnu.org Subject: bug#55652: please elaborate on diff -u -I RE Resent-From: Harald Dunkel Original-Sender: "Debbugs-submit" Resent-CC: bug-diffutils@gnu.org Resent-Date: Thu, 26 May 2022 09:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 55652 X-GNU-PR-Package: diffutils X-GNU-PR-Keywords: To: 55652@debbugs.gnu.org X-Debbugs-Original-To: bug-diffutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.165355655822143 (code B ref -1); Thu, 26 May 2022 09:16:02 +0000 Received: (at submit) by debbugs.gnu.org; 26 May 2022 09:15:58 +0000 Received: from localhost ([127.0.0.1]:57061 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nu9b4-0005l5-2v for submit@debbugs.gnu.org; Thu, 26 May 2022 05:15:58 -0400 Received: from lists.gnu.org ([209.51.188.17]:59040) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nu9b2-0005ky-NA for submit@debbugs.gnu.org; Thu, 26 May 2022 05:15:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nu9b2-0006uE-Ee for bug-diffutils@gnu.org; Thu, 26 May 2022 05:15:56 -0400 Received: from mordac.selfhost.de ([82.98.82.6]:55247 helo=outgoing.selfhost.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nu9b0-0000gN-FW for bug-diffutils@gnu.org; Thu, 26 May 2022 05:15:56 -0400 Received: (qmail 5098 invoked from network); 26 May 2022 09:15:39 -0000 Received: from unknown (HELO mailhost.afaics.de) (postmaster@xqrsonfo.mail.selfhost.de@87.160.253.127) by mailout.selfhost.de with ESMTPA; 26 May 2022 09:15:39 -0000 Received: from [10.42.100.14] (cecil.afaics.de [10.42.100.14]) by marvin.afaics.de (OpenSMTPD) with ESMTP id 41afc141; Thu, 26 May 2022 11:15:39 +0200 (CEST) Message-ID: <1d037236-055e-ffa8-7624-ede9ea58b009@afaics.de> Date: Thu, 26 May 2022 11:15:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US From: Harald Dunkel Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: none client-ip=82.98.82.6; envelope-from=harri@afaics.de; helo=outgoing.selfhost.de X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 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: -3.3 (---) Hi folks, I have hoped that diff -I '^[[:space:]]*\#' file1 file2 would ignore comment lines, but it doesn't work as I expected. Example: #!/bin/bash diff -version | head -1 echo -e '\t# comment 1' >/tmp/x1 echo -e '\t# comment 2' >/tmp/x2 diff -u -I '^[[:space:]]*\#' /tmp/x1 /tmp/x2 && echo 'no diffs' echo -e '' >>/tmp/x1 echo -e '' >>/tmp/x2 diff -u -I '^[[:space:]]*\#' /tmp/x1 /tmp/x2 && echo 'still no diffs' echo -e 'hello, world' >>/tmp/x2 diff -u -I '^[[:space:]]*\#' /tmp/x1 /tmp/x2 && echo 'no diffs' echo "diff --normal" diff -I '^[[:space:]]*\#' /tmp/x1 /tmp/x2 && echo 'no diffs' Output: diff (GNU diffutils) 3.8 no diffs still no diffs --- /tmp/x1 2022-05-26 10:54:36.187361365 +0200 +++ /tmp/x2 2022-05-26 10:54:36.191361276 +0200 @@ -1,2 +1,3 @@ - # comment 1 + # comment 2 +hello, world diff --normal 2a3 > hello, world This seems weird. Only 1 line has been appended to x2 before running diff the third time. It does not match the pattern. How comes diff -u reports 2 different lines, with an unchanged line in between? Is this as expected? Regards Harri From unknown Thu Jun 19 14:11:51 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Harald Dunkel Subject: bug#55652: closed (Re: [bug-diffutils] bug#55652: please elaborate on diff -u -I RE) Message-ID: References: <67d65b7a-1438-9033-e331-6791bc0043f8@cs.ucla.edu> <1d037236-055e-ffa8-7624-ede9ea58b009@afaics.de> X-Gnu-PR-Message: they-closed 55652 X-Gnu-PR-Package: diffutils Reply-To: 55652@debbugs.gnu.org Date: Fri, 27 May 2022 01:54:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1653616442-18321-1" This is a multi-part message in MIME format... ------------=_1653616442-18321-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #55652: please elaborate on diff -u -I RE which was filed against the diffutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 55652@debbugs.gnu.org. --=20 55652: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D55652 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1653616442-18321-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 55652-done) by debbugs.gnu.org; 27 May 2022 01:53:31 +0000 Received: from localhost ([127.0.0.1]:60383 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuPAQ-0004kl-Mx for submit@debbugs.gnu.org; Thu, 26 May 2022 21:53:30 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:45172) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuPAO-0004kU-GR for 55652-done@debbugs.gnu.org; Thu, 26 May 2022 21:53:29 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id AEE8F160137; Thu, 26 May 2022 18:53:21 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id oKohj5PLSSip; Thu, 26 May 2022 18:53:21 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 06766160139; Thu, 26 May 2022 18:53:21 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id pDdFxZ8Zdtf1; Thu, 26 May 2022 18:53:20 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id D81A8160137; Thu, 26 May 2022 18:53:20 -0700 (PDT) Message-ID: <67d65b7a-1438-9033-e331-6791bc0043f8@cs.ucla.edu> Date: Thu, 26 May 2022 18:53:20 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [bug-diffutils] bug#55652: please elaborate on diff -u -I RE Content-Language: en-US To: Harald Dunkel References: <1d037236-055e-ffa8-7624-ede9ea58b009@afaics.de> From: Paul Eggert Organization: UCLA Computer Science Department In-Reply-To: <1d037236-055e-ffa8-7624-ede9ea58b009@afaics.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55652-done Cc: 55652-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 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: -3.3 (---) On 5/26/22 02:15, Harald Dunkel wrote: > How comes diff -u > reports 2 different lines, with an unchanged line in between? What else can diff do? You asked for context, and the context lines differ. > Is this > as expected? Yes, the manual says: However, '-I' only ignores the insertion or deletion of lines that contain the regular expression if every changed line in the hunk--every insertion and every deletion--matches the regular expression. In other words, for each nonignorable change, 'diff' prints the complete set of changes in its vicinity, including the ignorable ones. One might add an option to make diff behave differently in this case, although it's not clear what the "right" behavior would be. In the meantime perhaps you can get by with "diff -U0 -Iwhatever". ------------=_1653616442-18321-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 26 May 2022 09:15:58 +0000 Received: from localhost ([127.0.0.1]:57061 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nu9b4-0005l5-2v for submit@debbugs.gnu.org; Thu, 26 May 2022 05:15:58 -0400 Received: from lists.gnu.org ([209.51.188.17]:59040) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nu9b2-0005ky-NA for submit@debbugs.gnu.org; Thu, 26 May 2022 05:15:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nu9b2-0006uE-Ee for bug-diffutils@gnu.org; Thu, 26 May 2022 05:15:56 -0400 Received: from mordac.selfhost.de ([82.98.82.6]:55247 helo=outgoing.selfhost.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nu9b0-0000gN-FW for bug-diffutils@gnu.org; Thu, 26 May 2022 05:15:56 -0400 Received: (qmail 5098 invoked from network); 26 May 2022 09:15:39 -0000 Received: from unknown (HELO mailhost.afaics.de) (postmaster@xqrsonfo.mail.selfhost.de@87.160.253.127) by mailout.selfhost.de with ESMTPA; 26 May 2022 09:15:39 -0000 Received: from [10.42.100.14] (cecil.afaics.de [10.42.100.14]) by marvin.afaics.de (OpenSMTPD) with ESMTP id 41afc141; Thu, 26 May 2022 11:15:39 +0200 (CEST) Message-ID: <1d037236-055e-ffa8-7624-ede9ea58b009@afaics.de> Date: Thu, 26 May 2022 11:15:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 To: bug-diffutils@gnu.org Content-Language: en-US From: Harald Dunkel Subject: please elaborate on diff -u -I RE Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: none client-ip=82.98.82.6; envelope-from=harri@afaics.de; helo=outgoing.selfhost.de X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 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: -3.3 (---) Hi folks, I have hoped that diff -I '^[[:space:]]*\#' file1 file2 would ignore comment lines, but it doesn't work as I expected. Example: #!/bin/bash diff -version | head -1 echo -e '\t# comment 1' >/tmp/x1 echo -e '\t# comment 2' >/tmp/x2 diff -u -I '^[[:space:]]*\#' /tmp/x1 /tmp/x2 && echo 'no diffs' echo -e '' >>/tmp/x1 echo -e '' >>/tmp/x2 diff -u -I '^[[:space:]]*\#' /tmp/x1 /tmp/x2 && echo 'still no diffs' echo -e 'hello, world' >>/tmp/x2 diff -u -I '^[[:space:]]*\#' /tmp/x1 /tmp/x2 && echo 'no diffs' echo "diff --normal" diff -I '^[[:space:]]*\#' /tmp/x1 /tmp/x2 && echo 'no diffs' Output: diff (GNU diffutils) 3.8 no diffs still no diffs --- /tmp/x1 2022-05-26 10:54:36.187361365 +0200 +++ /tmp/x2 2022-05-26 10:54:36.191361276 +0200 @@ -1,2 +1,3 @@ - # comment 1 + # comment 2 +hello, world diff --normal 2a3 > hello, world This seems weird. Only 1 line has been appended to x2 before running diff the third time. It does not match the pattern. How comes diff -u reports 2 different lines, with an unchanged line in between? Is this as expected? Regards Harri ------------=_1653616442-18321-1-- From unknown Thu Jun 19 14:11:51 2025 X-Loop: help-debbugs@gnu.org Subject: bug#55652: [bug-diffutils] bug#55652: please elaborate on diff -u -I RE Resent-From: Harald Dunkel Original-Sender: "Debbugs-submit" Resent-CC: bug-diffutils@gnu.org Resent-Date: Fri, 27 May 2022 07:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55652 X-GNU-PR-Package: diffutils X-GNU-PR-Keywords: To: Paul Eggert Cc: 55652-done@debbugs.gnu.org Received: via spool by 55652-done@debbugs.gnu.org id=D55652.165363804630836 (code D ref 55652); Fri, 27 May 2022 07:55:02 +0000 Received: (at 55652-done) by debbugs.gnu.org; 27 May 2022 07:54:06 +0000 Received: from localhost ([127.0.0.1]:60834 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuUnH-00080t-1m for submit@debbugs.gnu.org; Fri, 27 May 2022 03:54:06 -0400 Received: from mordac.selfhost.de ([82.98.82.6]:38037 helo=outgoing.selfhost.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuUnF-00080k-4W for 55652-done@debbugs.gnu.org; Fri, 27 May 2022 03:53:57 -0400 Received: (qmail 10322 invoked from network); 27 May 2022 07:53:55 -0000 Received: from unknown (HELO mailhost.afaics.de) (postmaster@xqrsonfo.mail.selfhost.de@87.160.253.127) by mailout.selfhost.de with ESMTPA; 27 May 2022 07:53:55 -0000 Received: from [10.42.100.14] (cecil.afaics.de [10.42.100.14]) by marvin.afaics.de (OpenSMTPD) with ESMTP id ffe075ec; Fri, 27 May 2022 09:53:55 +0200 (CEST) Message-ID: Date: Fri, 27 May 2022 09:53:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 From: Harald Dunkel References: <1d037236-055e-ffa8-7624-ede9ea58b009@afaics.de> <67d65b7a-1438-9033-e331-6791bc0043f8@cs.ucla.edu> Content-Language: en-US In-Reply-To: <67d65b7a-1438-9033-e331-6791bc0043f8@cs.ucla.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 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: -1.7 (-) Hi Paul, On 2022-05-27 03:53:20, Paul Eggert wrote: > On 5/26/22 02:15, Harald Dunkel wrote: >> How comes diff -u >> reports 2 different lines, with an unchanged line in between? > > What else can diff do? You asked for context, and the context lines differ. > It could show the old ignored lines as unchanged, of course. This would allow to apply the diff using patch. If it would show the new ignored lines instead, then you could only reverse apply the diff, which is much less likely to be useful. In the current implementation it is not useful at all. > >> Is this >> as expected? > > Yes, the manual says: > > However, '-I' only ignores the insertion or deletion of lines that > contain the regular expression if every changed line in the hunk--every > insertion and every deletion--matches the regular expression. In other > words, for each nonignorable change, 'diff' prints the complete set of > changes in its vicinity, including the ignorable ones. > Where did you find this? The man page for diffutils 3.8 doesn't tell. Regards Harri