regex - diff while ignoring patterns within a line, but not the entire line -


i have need compare 2 files, while ignoring changes within files. don't want ignore entire lines, portion of them. common case of timestamps on lines, there couple dozen other patterns need ignore too.

file1:

[2012-01-02] random text foo [2012-01-02] more output here 

file2:

[1999-01-01] random text bar [1999-01-01] more output here 

in example, want see difference on line number 1, not on line number 2.

using diff's -i option not work because ignores entire line. ideal output:

--- file1       2013-04-05 13:39:46.000000000 -0500 +++ file2       2013-04-05 13:39:56.000000000 -0500 @@ -1,2 +1,2 @@ -[2012-01-02] random text foo +[1999-01-01] random text bar  [2012-01-02] more output here 

i can pre-process these files sed:

sed -e's/^\[....-..-..\]//' < file1 > file1.tmp sed -e's/^\[....-..-..\]//' < file2 > file2.tmp diff -u file1.tmp file2.tmp 

but need put temporary files somewhere, , remember clean them afterwards. also, diff output no longer refers original filenames, , no longer emits original lines.

is there available variant of diff, or similar tool, can single command?

it isn't looking since i'm not sure how retain dates, solve couple of issues:

diff -u --label=file1 <(sed 's/^\[....-..-..\]//' file1) --label=file2 <(sed 's/^\[....-..-..\]//' file2) 

output:

--- file1 +++ file2 @@ -1,2 +1,2 @@ - random text foo + random text bar   more output here 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -