0

I have two text files, which are almost the same except for some changes on a few lines. I would like to merge these two files into a single text file, with differences highlighted, so that I can then view the merged file on an editor and manually review those differences.

This would be, I imagine, somewhat similar to what you typically get from an svn merge conflict. For example is file1 contains:

Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
Salami
Mortadella
Prosciutto
Creole Mustard
Bottom piece of bread

And file2 contains:

Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
Sauerkraut
Grilled Chicken
Creole Mustard
Bottom piece of bread

I would expect the merged file to contain something like:

Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
<<<<<<< .file1
Salami
Mortadella
Prosciutto
=======
Sauerkraut
Grilled Chicken
>>>>>>> .file2
Creole Mustard
Bottom piece of bread

Maybe there is a diff option for this that I'm missing?

2 Answers 2

1

Final Version, with OP's addition of --changed-group-format

diff old-file new-file --old-group-format='<<<<<<< .old
%<=======
' --new-group-format='=======
%>>>>>>>> .new
' --changed-group-format='<<<<<<< .old
%<=======
%>>>>>>>> .new
'

which leads to

Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
<<<<<< .old
Salami
Mortadella
Prosciutto
=====
Sauerkraut
Grilled Chicken
>>>>>>> .new
Creole Mustard
Bottom piece of bread
1
  • Thanks! This is what I was looking for. I would keep the info that, if in a hurry, diff old new -D CHANGED would be good enough. While, to better match the output suggested on my own question, one would also need to supply --changed-group-format as shown here. Commented Mar 24, 2014 at 13:57
0

Are you searching for this? You can use WinMerge or UltraEdit for this..

2
  • Just reword your question, e.g. you could say something like "If you're under Windows and you only want some visualization for yourself (no files to be saved), then you might want to have a look at WinMerge." Also remember that talking links are always better, not just for SEO, but for readers as well. :)
    – Mario
    Commented Mar 24, 2014 at 9:40
  • @Mario:I was about to edit the answer after getting conformation from the questioner.. Done that now..
    – Vysakh
    Commented Mar 24, 2014 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .