I have two large files consisting mainly of numbers in matrix form, and I'd like to use diff (or similar command) to compare these files and determine which numbers are different.
Unfortunately, quite a lot of these numbers differ only by sign, and I'm not interested in those differences. I only care when two numbers are different in magnitude. (i.e. I want 0.523 vs. 0.623
, but NOT 0.523 vs. -0.523
)
Is it possible to make diff ignore the sign and only print numbers that are different in magnitude?
EDIT: Some input examples, as requested:
File 1:
21 -0.0081318 0.0000000 0.0000000 0.0000000 -0.0138079
22 0.0000000 0.0000000 0.0000000 0.1156119 0.0000000
23 0.0000000 0.0047536 0.0000000 0.0000000 0.0000000
File 2:
21 -0.0081318 0.0000000 0.0000000 0.0000000 0.0032533
22 0.0000000 0.0000000 0.0000000 -0.0250637 0.0000000
23 0.0000000 -0.0047536 0.0000000 0.0000000 0.0000000
Assuming my files are formated mostly like this (except much, MUCH longer), I want to print out the differences, but ignore such differences when they're only in sign. For example, I don't care for 0.0047536 vs. -0.0047536, but I do want to print 0.1156119 vs. -0.0250637.
tr
, orsed
?GNU octave
) or a suitable programming language (e.g.FORTRAN
) for this task. Especially if it is large files. BTW:diff
compares whole files or strings and does so line by line, not word by word. Not the right tool here.