GNU bug report logs -
#55652
please elaborate on diff -u -I RE
Previous Next
Reported by: Harald Dunkel <harri <at> afaics.de>
Date: Thu, 26 May 2022 09:16:02 UTC
Severity: normal
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
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
This bug report was last modified 3 years and 15 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.