How to ignore differences between negative signs of numbers in the diff command?

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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.
linux diff numeric-data
New contributor
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
 |Â
show 2 more comments
up vote
0
down vote
favorite
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.
linux diff numeric-data
New contributor
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
What does "mainly in matrix form" mean? An input sample might help, as well as an output sample.
â RudiC
Oct 3 at 21:20
Could you just delete / eliminate all minusses from the input? Withtr, orsed?
â RudiC
Oct 3 at 21:21
2
Please at least provide examples of input and desired output. Do you only want to know IF they differ or the difference or both values or a combination thereof. How should it be displayed? Also I'd suggest referring to either a mathematics suite (e.g.GNU octave) or a suitable programming language (e.g.FORTRAN) for this task. Especially if it is large files. BTW:diffcompares whole files or strings and does so line by line, not word by word. Not the right tool here.
â Fiximan
Oct 3 at 21:39
@RudiC Could you show me how I could eliminate all minuses from the input and still leave the format of the text intact ?
â johnymm
Oct 3 at 23:27
Do you know the matrix sizes? Do they vary? How should the output look like?
â Fiximan
Oct 3 at 23:36
 |Â
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
linux diff numeric-data
New contributor
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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.
linux diff numeric-data
linux diff numeric-data
New contributor
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Oct 4 at 14:34
New contributor
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Oct 3 at 21:18
johnymm
61
61
New contributor
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
johnymm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
What does "mainly in matrix form" mean? An input sample might help, as well as an output sample.
â RudiC
Oct 3 at 21:20
Could you just delete / eliminate all minusses from the input? Withtr, orsed?
â RudiC
Oct 3 at 21:21
2
Please at least provide examples of input and desired output. Do you only want to know IF they differ or the difference or both values or a combination thereof. How should it be displayed? Also I'd suggest referring to either a mathematics suite (e.g.GNU octave) or a suitable programming language (e.g.FORTRAN) for this task. Especially if it is large files. BTW:diffcompares whole files or strings and does so line by line, not word by word. Not the right tool here.
â Fiximan
Oct 3 at 21:39
@RudiC Could you show me how I could eliminate all minuses from the input and still leave the format of the text intact ?
â johnymm
Oct 3 at 23:27
Do you know the matrix sizes? Do they vary? How should the output look like?
â Fiximan
Oct 3 at 23:36
 |Â
show 2 more comments
2
What does "mainly in matrix form" mean? An input sample might help, as well as an output sample.
â RudiC
Oct 3 at 21:20
Could you just delete / eliminate all minusses from the input? Withtr, orsed?
â RudiC
Oct 3 at 21:21
2
Please at least provide examples of input and desired output. Do you only want to know IF they differ or the difference or both values or a combination thereof. How should it be displayed? Also I'd suggest referring to either a mathematics suite (e.g.GNU octave) or a suitable programming language (e.g.FORTRAN) for this task. Especially if it is large files. BTW:diffcompares whole files or strings and does so line by line, not word by word. Not the right tool here.
â Fiximan
Oct 3 at 21:39
@RudiC Could you show me how I could eliminate all minuses from the input and still leave the format of the text intact ?
â johnymm
Oct 3 at 23:27
Do you know the matrix sizes? Do they vary? How should the output look like?
â Fiximan
Oct 3 at 23:36
2
2
What does "mainly in matrix form" mean? An input sample might help, as well as an output sample.
â RudiC
Oct 3 at 21:20
What does "mainly in matrix form" mean? An input sample might help, as well as an output sample.
â RudiC
Oct 3 at 21:20
Could you just delete / eliminate all minusses from the input? With
tr, or sed?â RudiC
Oct 3 at 21:21
Could you just delete / eliminate all minusses from the input? With
tr, or sed?â RudiC
Oct 3 at 21:21
2
2
Please at least provide examples of input and desired output. Do you only want to know IF they differ or the difference or both values or a combination thereof. How should it be displayed? Also I'd suggest referring to either a mathematics suite (e.g.
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.â Fiximan
Oct 3 at 21:39
Please at least provide examples of input and desired output. Do you only want to know IF they differ or the difference or both values or a combination thereof. How should it be displayed? Also I'd suggest referring to either a mathematics suite (e.g.
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.â Fiximan
Oct 3 at 21:39
@RudiC Could you show me how I could eliminate all minuses from the input and still leave the format of the text intact ?
â johnymm
Oct 3 at 23:27
@RudiC Could you show me how I could eliminate all minuses from the input and still leave the format of the text intact ?
â johnymm
Oct 3 at 23:27
Do you know the matrix sizes? Do they vary? How should the output look like?
â Fiximan
Oct 3 at 23:36
Do you know the matrix sizes? Do they vary? How should the output look like?
â Fiximan
Oct 3 at 23:36
 |Â
show 2 more comments
3 Answers
3
active
oldest
votes
up vote
3
down vote
Given your shell provided "process substitution" (likes recent bashes), try
diff <(tr '-' ' ' <file1) <(tr '-' ' '<file2)
1,2c1,2
< 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0138079
< 22 0.0000000 0.0000000 0.0000000 0.1156119 0.0000000
---
> 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0032533
> 22 0.0000000 0.0000000 0.0000000 0.0250637 0.0000000
This also works. Thanks! I can't believe it was this easy haha. I should be more familiar with basic Unix commands.
â johnymm
Oct 4 at 14:45
add a comment |Â
up vote
1
down vote
$ xdiff() diff -bu <($1 "$2") <($1 "$3");
$ xdiff 'sed s/-([.0-9])/1/g' file1 file2
you can do other normalization to the data. for instance, to treat all of 0.01, .01, -.0100, -.01e as the same:
$ norm() awk 'for(i=1;i<=NF;i++)$i=$i<0?-$i:+$i;print' "$@";
$ xdiff norm file1 file2
This approach seems to delete the minuses, but also displaces the entire line to the left - so diff still displays the line. Is it possible to replace the the minus with an empty space, so the format remains the same ?
â johnymm
Oct 4 at 0:52
1
the-boption given to diff should tell it to treat any amount of whitespace as the same, so it shouldn't display the line. but yes, you can replace-by a space by adding a space before the1(eg seds/../ 1/g).
â mosvy
Oct 4 at 0:58
I'm not on my computer right now but I'll try it as soon as I can and let you know if it works.
â johnymm
Oct 4 at 1:00
When I add a space before "1" it gives me the error: sed: -e expression #1, char 14: unterminated `s' command
â johnymm
Oct 4 at 4:47
yes, it will be split with IFS. it'll work if you put it in a function though:norm() sed 's/-/ /g' "$@"; ; xdiff norm file1 file2. rather than extend that minimal xdiff example, you could use the script from my answer here like this:x 'diff -bu' "sed 's/-/ /g'" file1 file2
â mosvy
Oct 4 at 4:57
 |Â
show 1 more comment
up vote
0
down vote
To print lines from file2 whose corresponding absolute values differ from the corresponding fields from the same line in file1, save the lines from file1 in memory, the compare their absolute values:
function abs(x)
return x < 0 ? -x : x;
# file 1
NR == FNR
file1[$1]=$2" "$3" "$4" "$5" "$6
# file 2
NR != FNR
Save that in a file, then run awk -f /path/to/that/file file1 file2
I'm not sure what you mean by "save the lines from file1 in memory"
â johnymm
Oct 4 at 4:51
@johnymm it meansfile1is completely saved to RAM, thenfile2is read (more or less) line by line and the corresponding lines are compared. Iffile1exceeds your PC's memory, you will have to split the files beforehand.
â Fiximan
Oct 4 at 10:46
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Given your shell provided "process substitution" (likes recent bashes), try
diff <(tr '-' ' ' <file1) <(tr '-' ' '<file2)
1,2c1,2
< 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0138079
< 22 0.0000000 0.0000000 0.0000000 0.1156119 0.0000000
---
> 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0032533
> 22 0.0000000 0.0000000 0.0000000 0.0250637 0.0000000
This also works. Thanks! I can't believe it was this easy haha. I should be more familiar with basic Unix commands.
â johnymm
Oct 4 at 14:45
add a comment |Â
up vote
3
down vote
Given your shell provided "process substitution" (likes recent bashes), try
diff <(tr '-' ' ' <file1) <(tr '-' ' '<file2)
1,2c1,2
< 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0138079
< 22 0.0000000 0.0000000 0.0000000 0.1156119 0.0000000
---
> 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0032533
> 22 0.0000000 0.0000000 0.0000000 0.0250637 0.0000000
This also works. Thanks! I can't believe it was this easy haha. I should be more familiar with basic Unix commands.
â johnymm
Oct 4 at 14:45
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Given your shell provided "process substitution" (likes recent bashes), try
diff <(tr '-' ' ' <file1) <(tr '-' ' '<file2)
1,2c1,2
< 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0138079
< 22 0.0000000 0.0000000 0.0000000 0.1156119 0.0000000
---
> 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0032533
> 22 0.0000000 0.0000000 0.0000000 0.0250637 0.0000000
Given your shell provided "process substitution" (likes recent bashes), try
diff <(tr '-' ' ' <file1) <(tr '-' ' '<file2)
1,2c1,2
< 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0138079
< 22 0.0000000 0.0000000 0.0000000 0.1156119 0.0000000
---
> 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0032533
> 22 0.0000000 0.0000000 0.0000000 0.0250637 0.0000000
answered Oct 4 at 8:39
RudiC
1,84219
1,84219
This also works. Thanks! I can't believe it was this easy haha. I should be more familiar with basic Unix commands.
â johnymm
Oct 4 at 14:45
add a comment |Â
This also works. Thanks! I can't believe it was this easy haha. I should be more familiar with basic Unix commands.
â johnymm
Oct 4 at 14:45
This also works. Thanks! I can't believe it was this easy haha. I should be more familiar with basic Unix commands.
â johnymm
Oct 4 at 14:45
This also works. Thanks! I can't believe it was this easy haha. I should be more familiar with basic Unix commands.
â johnymm
Oct 4 at 14:45
add a comment |Â
up vote
1
down vote
$ xdiff() diff -bu <($1 "$2") <($1 "$3");
$ xdiff 'sed s/-([.0-9])/1/g' file1 file2
you can do other normalization to the data. for instance, to treat all of 0.01, .01, -.0100, -.01e as the same:
$ norm() awk 'for(i=1;i<=NF;i++)$i=$i<0?-$i:+$i;print' "$@";
$ xdiff norm file1 file2
This approach seems to delete the minuses, but also displaces the entire line to the left - so diff still displays the line. Is it possible to replace the the minus with an empty space, so the format remains the same ?
â johnymm
Oct 4 at 0:52
1
the-boption given to diff should tell it to treat any amount of whitespace as the same, so it shouldn't display the line. but yes, you can replace-by a space by adding a space before the1(eg seds/../ 1/g).
â mosvy
Oct 4 at 0:58
I'm not on my computer right now but I'll try it as soon as I can and let you know if it works.
â johnymm
Oct 4 at 1:00
When I add a space before "1" it gives me the error: sed: -e expression #1, char 14: unterminated `s' command
â johnymm
Oct 4 at 4:47
yes, it will be split with IFS. it'll work if you put it in a function though:norm() sed 's/-/ /g' "$@"; ; xdiff norm file1 file2. rather than extend that minimal xdiff example, you could use the script from my answer here like this:x 'diff -bu' "sed 's/-/ /g'" file1 file2
â mosvy
Oct 4 at 4:57
 |Â
show 1 more comment
up vote
1
down vote
$ xdiff() diff -bu <($1 "$2") <($1 "$3");
$ xdiff 'sed s/-([.0-9])/1/g' file1 file2
you can do other normalization to the data. for instance, to treat all of 0.01, .01, -.0100, -.01e as the same:
$ norm() awk 'for(i=1;i<=NF;i++)$i=$i<0?-$i:+$i;print' "$@";
$ xdiff norm file1 file2
This approach seems to delete the minuses, but also displaces the entire line to the left - so diff still displays the line. Is it possible to replace the the minus with an empty space, so the format remains the same ?
â johnymm
Oct 4 at 0:52
1
the-boption given to diff should tell it to treat any amount of whitespace as the same, so it shouldn't display the line. but yes, you can replace-by a space by adding a space before the1(eg seds/../ 1/g).
â mosvy
Oct 4 at 0:58
I'm not on my computer right now but I'll try it as soon as I can and let you know if it works.
â johnymm
Oct 4 at 1:00
When I add a space before "1" it gives me the error: sed: -e expression #1, char 14: unterminated `s' command
â johnymm
Oct 4 at 4:47
yes, it will be split with IFS. it'll work if you put it in a function though:norm() sed 's/-/ /g' "$@"; ; xdiff norm file1 file2. rather than extend that minimal xdiff example, you could use the script from my answer here like this:x 'diff -bu' "sed 's/-/ /g'" file1 file2
â mosvy
Oct 4 at 4:57
 |Â
show 1 more comment
up vote
1
down vote
up vote
1
down vote
$ xdiff() diff -bu <($1 "$2") <($1 "$3");
$ xdiff 'sed s/-([.0-9])/1/g' file1 file2
you can do other normalization to the data. for instance, to treat all of 0.01, .01, -.0100, -.01e as the same:
$ norm() awk 'for(i=1;i<=NF;i++)$i=$i<0?-$i:+$i;print' "$@";
$ xdiff norm file1 file2
$ xdiff() diff -bu <($1 "$2") <($1 "$3");
$ xdiff 'sed s/-([.0-9])/1/g' file1 file2
you can do other normalization to the data. for instance, to treat all of 0.01, .01, -.0100, -.01e as the same:
$ norm() awk 'for(i=1;i<=NF;i++)$i=$i<0?-$i:+$i;print' "$@";
$ xdiff norm file1 file2
edited Oct 4 at 0:10
answered Oct 3 at 21:58
mosvy
1,922110
1,922110
This approach seems to delete the minuses, but also displaces the entire line to the left - so diff still displays the line. Is it possible to replace the the minus with an empty space, so the format remains the same ?
â johnymm
Oct 4 at 0:52
1
the-boption given to diff should tell it to treat any amount of whitespace as the same, so it shouldn't display the line. but yes, you can replace-by a space by adding a space before the1(eg seds/../ 1/g).
â mosvy
Oct 4 at 0:58
I'm not on my computer right now but I'll try it as soon as I can and let you know if it works.
â johnymm
Oct 4 at 1:00
When I add a space before "1" it gives me the error: sed: -e expression #1, char 14: unterminated `s' command
â johnymm
Oct 4 at 4:47
yes, it will be split with IFS. it'll work if you put it in a function though:norm() sed 's/-/ /g' "$@"; ; xdiff norm file1 file2. rather than extend that minimal xdiff example, you could use the script from my answer here like this:x 'diff -bu' "sed 's/-/ /g'" file1 file2
â mosvy
Oct 4 at 4:57
 |Â
show 1 more comment
This approach seems to delete the minuses, but also displaces the entire line to the left - so diff still displays the line. Is it possible to replace the the minus with an empty space, so the format remains the same ?
â johnymm
Oct 4 at 0:52
1
the-boption given to diff should tell it to treat any amount of whitespace as the same, so it shouldn't display the line. but yes, you can replace-by a space by adding a space before the1(eg seds/../ 1/g).
â mosvy
Oct 4 at 0:58
I'm not on my computer right now but I'll try it as soon as I can and let you know if it works.
â johnymm
Oct 4 at 1:00
When I add a space before "1" it gives me the error: sed: -e expression #1, char 14: unterminated `s' command
â johnymm
Oct 4 at 4:47
yes, it will be split with IFS. it'll work if you put it in a function though:norm() sed 's/-/ /g' "$@"; ; xdiff norm file1 file2. rather than extend that minimal xdiff example, you could use the script from my answer here like this:x 'diff -bu' "sed 's/-/ /g'" file1 file2
â mosvy
Oct 4 at 4:57
This approach seems to delete the minuses, but also displaces the entire line to the left - so diff still displays the line. Is it possible to replace the the minus with an empty space, so the format remains the same ?
â johnymm
Oct 4 at 0:52
This approach seems to delete the minuses, but also displaces the entire line to the left - so diff still displays the line. Is it possible to replace the the minus with an empty space, so the format remains the same ?
â johnymm
Oct 4 at 0:52
1
1
the
-b option given to diff should tell it to treat any amount of whitespace as the same, so it shouldn't display the line. but yes, you can replace - by a space by adding a space before the 1 (eg sed s/../ 1/g).â mosvy
Oct 4 at 0:58
the
-b option given to diff should tell it to treat any amount of whitespace as the same, so it shouldn't display the line. but yes, you can replace - by a space by adding a space before the 1 (eg sed s/../ 1/g).â mosvy
Oct 4 at 0:58
I'm not on my computer right now but I'll try it as soon as I can and let you know if it works.
â johnymm
Oct 4 at 1:00
I'm not on my computer right now but I'll try it as soon as I can and let you know if it works.
â johnymm
Oct 4 at 1:00
When I add a space before "1" it gives me the error: sed: -e expression #1, char 14: unterminated `s' command
â johnymm
Oct 4 at 4:47
When I add a space before "1" it gives me the error: sed: -e expression #1, char 14: unterminated `s' command
â johnymm
Oct 4 at 4:47
yes, it will be split with IFS. it'll work if you put it in a function though:
norm() sed 's/-/ /g' "$@"; ; xdiff norm file1 file2. rather than extend that minimal xdiff example, you could use the script from my answer here like this: x 'diff -bu' "sed 's/-/ /g'" file1 file2â mosvy
Oct 4 at 4:57
yes, it will be split with IFS. it'll work if you put it in a function though:
norm() sed 's/-/ /g' "$@"; ; xdiff norm file1 file2. rather than extend that minimal xdiff example, you could use the script from my answer here like this: x 'diff -bu' "sed 's/-/ /g'" file1 file2â mosvy
Oct 4 at 4:57
 |Â
show 1 more comment
up vote
0
down vote
To print lines from file2 whose corresponding absolute values differ from the corresponding fields from the same line in file1, save the lines from file1 in memory, the compare their absolute values:
function abs(x)
return x < 0 ? -x : x;
# file 1
NR == FNR
file1[$1]=$2" "$3" "$4" "$5" "$6
# file 2
NR != FNR
Save that in a file, then run awk -f /path/to/that/file file1 file2
I'm not sure what you mean by "save the lines from file1 in memory"
â johnymm
Oct 4 at 4:51
@johnymm it meansfile1is completely saved to RAM, thenfile2is read (more or less) line by line and the corresponding lines are compared. Iffile1exceeds your PC's memory, you will have to split the files beforehand.
â Fiximan
Oct 4 at 10:46
add a comment |Â
up vote
0
down vote
To print lines from file2 whose corresponding absolute values differ from the corresponding fields from the same line in file1, save the lines from file1 in memory, the compare their absolute values:
function abs(x)
return x < 0 ? -x : x;
# file 1
NR == FNR
file1[$1]=$2" "$3" "$4" "$5" "$6
# file 2
NR != FNR
Save that in a file, then run awk -f /path/to/that/file file1 file2
I'm not sure what you mean by "save the lines from file1 in memory"
â johnymm
Oct 4 at 4:51
@johnymm it meansfile1is completely saved to RAM, thenfile2is read (more or less) line by line and the corresponding lines are compared. Iffile1exceeds your PC's memory, you will have to split the files beforehand.
â Fiximan
Oct 4 at 10:46
add a comment |Â
up vote
0
down vote
up vote
0
down vote
To print lines from file2 whose corresponding absolute values differ from the corresponding fields from the same line in file1, save the lines from file1 in memory, the compare their absolute values:
function abs(x)
return x < 0 ? -x : x;
# file 1
NR == FNR
file1[$1]=$2" "$3" "$4" "$5" "$6
# file 2
NR != FNR
Save that in a file, then run awk -f /path/to/that/file file1 file2
To print lines from file2 whose corresponding absolute values differ from the corresponding fields from the same line in file1, save the lines from file1 in memory, the compare their absolute values:
function abs(x)
return x < 0 ? -x : x;
# file 1
NR == FNR
file1[$1]=$2" "$3" "$4" "$5" "$6
# file 2
NR != FNR
Save that in a file, then run awk -f /path/to/that/file file1 file2
answered Oct 4 at 1:28
Jeff Schaller
33.6k851113
33.6k851113
I'm not sure what you mean by "save the lines from file1 in memory"
â johnymm
Oct 4 at 4:51
@johnymm it meansfile1is completely saved to RAM, thenfile2is read (more or less) line by line and the corresponding lines are compared. Iffile1exceeds your PC's memory, you will have to split the files beforehand.
â Fiximan
Oct 4 at 10:46
add a comment |Â
I'm not sure what you mean by "save the lines from file1 in memory"
â johnymm
Oct 4 at 4:51
@johnymm it meansfile1is completely saved to RAM, thenfile2is read (more or less) line by line and the corresponding lines are compared. Iffile1exceeds your PC's memory, you will have to split the files beforehand.
â Fiximan
Oct 4 at 10:46
I'm not sure what you mean by "save the lines from file1 in memory"
â johnymm
Oct 4 at 4:51
I'm not sure what you mean by "save the lines from file1 in memory"
â johnymm
Oct 4 at 4:51
@johnymm it means
file1 is completely saved to RAM, then file2 is read (more or less) line by line and the corresponding lines are compared. If file1 exceeds your PC's memory, you will have to split the files beforehand.â Fiximan
Oct 4 at 10:46
@johnymm it means
file1 is completely saved to RAM, then file2 is read (more or less) line by line and the corresponding lines are compared. If file1 exceeds your PC's memory, you will have to split the files beforehand.â Fiximan
Oct 4 at 10:46
add a comment |Â
johnymm is a new contributor. Be nice, and check out our Code of Conduct.
johnymm is a new contributor. Be nice, and check out our Code of Conduct.
johnymm is a new contributor. Be nice, and check out our Code of Conduct.
johnymm is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473092%2fhow-to-ignore-differences-between-negative-signs-of-numbers-in-the-diff-command%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
What does "mainly in matrix form" mean? An input sample might help, as well as an output sample.
â RudiC
Oct 3 at 21:20
Could you just delete / eliminate all minusses from the input? With
tr, orsed?â RudiC
Oct 3 at 21:21
2
Please at least provide examples of input and desired output. Do you only want to know IF they differ or the difference or both values or a combination thereof. How should it be displayed? Also I'd suggest referring to either a mathematics suite (e.g.
GNU octave) or a suitable programming language (e.g.FORTRAN) for this task. Especially if it is large files. BTW:diffcompares whole files or strings and does so line by line, not word by word. Not the right tool here.â Fiximan
Oct 3 at 21:39
@RudiC Could you show me how I could eliminate all minuses from the input and still leave the format of the text intact ?
â johnymm
Oct 3 at 23:27
Do you know the matrix sizes? Do they vary? How should the output look like?
â Fiximan
Oct 3 at 23:36