I often have to compare two files, ignoring some changes in these files. I do not want to ignore whole lines, but part of them. The most common case of this is time stamping on lines, but there are dozens of other patterns that I also need to ignore.
File1:
[2012-01-02] Some random text foo
[2012-01-02] More output here
File2:
[1999-01-01] Some random text bar
[1999-01-01] More output here
In this example, I want to see the difference in line number 1, but not in line number 2.
Using the diff -I option will not work because it ignores the entire line. Ideal yield:
@@ -1,2 +1,2 @@
-[2012-01-02] Some random text foo
+[1999-01-01] Some random text bar
[2012-01-02] More output here
I can pre-process these files with sed:
sed -e's/^\[....-..-..\]//' < file1 > file1.tmp
sed -e's/^\[....-..-..\]//' < file2 > file2.tmp
diff -u file1.tmp file2.tmp
but then I need to put these temporary files somewhere and don't forget to clean them later. In addition, my diff output no longer applies to the original file names and no longer emits the original lines.
diff , ?