How does `diff` decide whether a difference is change (i.e. replacement) or combination of addition and deletion?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-3
down vote

favorite












I was wondering how diff decides whether a difference is change (i.e. replacement) or combination of addition and deletion?



The best I can find from diffutils' manual is




‘fct’



Replace the lines in range f of the first file with lines in range t
of the second file. This is like a combined add and delete, but more
compact. For example, ‘5,7c8,10’ means change lines 5–7 of file 1 to
read as lines 8–10 of file 2; or,if changing file 2 into file 1,
change lines 8–10 of file 2 to read as lines 5–7 of file
1.




For example, I have two files, each having four lines



$ paste f2 f3
0 1
1 2
3 3
5 6


and I diff them



$ diff f2 f3
1d0
< 0
2a2
> 2
4c4
< 5
---
> 6


Why is



1d0
< 0
2a2
> 2


not



1,2c1,2
< 0
< 1
---
> 1
> 2


instead?



The alternative I gave and the diff output both have 3 as the common line, but my alternative treats the different lines before the common line as c i.e. replacement, while the diff output treats them as a combination of deletion and addition.










share|improve this question























  • If you read the manual, it says diff tries to minimize the total hunk size by finding large sequences of common lines interspersed with small hunks of differing lines... there are even examples etc...
    – don_crissti
    4 hours ago










  • Thanks. Can you be more specific when it comes to my questions?
    – Tim
    4 hours ago










  • No. I think the manual is very clear, just read the hunks subsection that I linked to...
    – don_crissti
    4 hours ago











  • I have. But I can't relate it here. I was wondering whether I am missing something, or you actually miss my question?
    – Tim
    4 hours ago











  • Well, I cannot understand most of your questions but this one is pretty clear... And so is the answer in the manual: In general, there are many ways to match up lines between two given files.
    – don_crissti
    4 hours ago














up vote
-3
down vote

favorite












I was wondering how diff decides whether a difference is change (i.e. replacement) or combination of addition and deletion?



The best I can find from diffutils' manual is




‘fct’



Replace the lines in range f of the first file with lines in range t
of the second file. This is like a combined add and delete, but more
compact. For example, ‘5,7c8,10’ means change lines 5–7 of file 1 to
read as lines 8–10 of file 2; or,if changing file 2 into file 1,
change lines 8–10 of file 2 to read as lines 5–7 of file
1.




For example, I have two files, each having four lines



$ paste f2 f3
0 1
1 2
3 3
5 6


and I diff them



$ diff f2 f3
1d0
< 0
2a2
> 2
4c4
< 5
---
> 6


Why is



1d0
< 0
2a2
> 2


not



1,2c1,2
< 0
< 1
---
> 1
> 2


instead?



The alternative I gave and the diff output both have 3 as the common line, but my alternative treats the different lines before the common line as c i.e. replacement, while the diff output treats them as a combination of deletion and addition.










share|improve this question























  • If you read the manual, it says diff tries to minimize the total hunk size by finding large sequences of common lines interspersed with small hunks of differing lines... there are even examples etc...
    – don_crissti
    4 hours ago










  • Thanks. Can you be more specific when it comes to my questions?
    – Tim
    4 hours ago










  • No. I think the manual is very clear, just read the hunks subsection that I linked to...
    – don_crissti
    4 hours ago











  • I have. But I can't relate it here. I was wondering whether I am missing something, or you actually miss my question?
    – Tim
    4 hours ago











  • Well, I cannot understand most of your questions but this one is pretty clear... And so is the answer in the manual: In general, there are many ways to match up lines between two given files.
    – don_crissti
    4 hours ago












up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











I was wondering how diff decides whether a difference is change (i.e. replacement) or combination of addition and deletion?



The best I can find from diffutils' manual is




‘fct’



Replace the lines in range f of the first file with lines in range t
of the second file. This is like a combined add and delete, but more
compact. For example, ‘5,7c8,10’ means change lines 5–7 of file 1 to
read as lines 8–10 of file 2; or,if changing file 2 into file 1,
change lines 8–10 of file 2 to read as lines 5–7 of file
1.




For example, I have two files, each having four lines



$ paste f2 f3
0 1
1 2
3 3
5 6


and I diff them



$ diff f2 f3
1d0
< 0
2a2
> 2
4c4
< 5
---
> 6


Why is



1d0
< 0
2a2
> 2


not



1,2c1,2
< 0
< 1
---
> 1
> 2


instead?



The alternative I gave and the diff output both have 3 as the common line, but my alternative treats the different lines before the common line as c i.e. replacement, while the diff output treats them as a combination of deletion and addition.










share|improve this question















I was wondering how diff decides whether a difference is change (i.e. replacement) or combination of addition and deletion?



The best I can find from diffutils' manual is




‘fct’



Replace the lines in range f of the first file with lines in range t
of the second file. This is like a combined add and delete, but more
compact. For example, ‘5,7c8,10’ means change lines 5–7 of file 1 to
read as lines 8–10 of file 2; or,if changing file 2 into file 1,
change lines 8–10 of file 2 to read as lines 5–7 of file
1.




For example, I have two files, each having four lines



$ paste f2 f3
0 1
1 2
3 3
5 6


and I diff them



$ diff f2 f3
1d0
< 0
2a2
> 2
4c4
< 5
---
> 6


Why is



1d0
< 0
2a2
> 2


not



1,2c1,2
< 0
< 1
---
> 1
> 2


instead?



The alternative I gave and the diff output both have 3 as the common line, but my alternative treats the different lines before the common line as c i.e. replacement, while the diff output treats them as a combination of deletion and addition.







text-processing diff






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago

























asked 4 hours ago









Tim

24.7k70239431




24.7k70239431











  • If you read the manual, it says diff tries to minimize the total hunk size by finding large sequences of common lines interspersed with small hunks of differing lines... there are even examples etc...
    – don_crissti
    4 hours ago










  • Thanks. Can you be more specific when it comes to my questions?
    – Tim
    4 hours ago










  • No. I think the manual is very clear, just read the hunks subsection that I linked to...
    – don_crissti
    4 hours ago











  • I have. But I can't relate it here. I was wondering whether I am missing something, or you actually miss my question?
    – Tim
    4 hours ago











  • Well, I cannot understand most of your questions but this one is pretty clear... And so is the answer in the manual: In general, there are many ways to match up lines between two given files.
    – don_crissti
    4 hours ago
















  • If you read the manual, it says diff tries to minimize the total hunk size by finding large sequences of common lines interspersed with small hunks of differing lines... there are even examples etc...
    – don_crissti
    4 hours ago










  • Thanks. Can you be more specific when it comes to my questions?
    – Tim
    4 hours ago










  • No. I think the manual is very clear, just read the hunks subsection that I linked to...
    – don_crissti
    4 hours ago











  • I have. But I can't relate it here. I was wondering whether I am missing something, or you actually miss my question?
    – Tim
    4 hours ago











  • Well, I cannot understand most of your questions but this one is pretty clear... And so is the answer in the manual: In general, there are many ways to match up lines between two given files.
    – don_crissti
    4 hours ago















If you read the manual, it says diff tries to minimize the total hunk size by finding large sequences of common lines interspersed with small hunks of differing lines... there are even examples etc...
– don_crissti
4 hours ago




If you read the manual, it says diff tries to minimize the total hunk size by finding large sequences of common lines interspersed with small hunks of differing lines... there are even examples etc...
– don_crissti
4 hours ago












Thanks. Can you be more specific when it comes to my questions?
– Tim
4 hours ago




Thanks. Can you be more specific when it comes to my questions?
– Tim
4 hours ago












No. I think the manual is very clear, just read the hunks subsection that I linked to...
– don_crissti
4 hours ago





No. I think the manual is very clear, just read the hunks subsection that I linked to...
– don_crissti
4 hours ago













I have. But I can't relate it here. I was wondering whether I am missing something, or you actually miss my question?
– Tim
4 hours ago





I have. But I can't relate it here. I was wondering whether I am missing something, or you actually miss my question?
– Tim
4 hours ago













Well, I cannot understand most of your questions but this one is pretty clear... And so is the answer in the manual: In general, there are many ways to match up lines between two given files.
– don_crissti
4 hours ago




Well, I cannot understand most of your questions but this one is pretty clear... And so is the answer in the manual: In general, there are many ways to match up lines between two given files.
– don_crissti
4 hours ago















active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480848%2fhow-does-diff-decide-whether-a-difference-is-change-i-e-replacement-or-comb%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480848%2fhow-does-diff-decide-whether-a-difference-is-change-i-e-replacement-or-comb%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay