I have two files with slight differences. A normal diff
will show me the differences between the files. With -c
or -u
I can add an amount of context to each hunk. What options can I pass to diff
to see every unchanged line alongside the changes, and get the diff as a single, large hunk?
You can also override the diff formatting behavior to get your desired behavior without using side-by-side mode:
diff --new-line-format='+%L' --old-line-format='-%L' --unchanged-line-format=' %L' file1 file2
This command will show you the full file as context and be closest in format to diff -u file1 file2
Use the "-y" option for full side by side output
diff -y file1 file2
Will give you output something like
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit. * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. * Praesent fringilla facilisis pede. * Praesent fringilla facilisis pede. * Nulla sit amet tellus id massa luctus pellentesque. * Nulla sit amet tellus id massa luctus pellentesque. * Pellentesque a neque nec elit aliquam congue. * Pellentesque a neque nec elit aliquam congue. * Quisque rhoncus ultricies elit. * Quisque rhoncus ultricies elit. * Pellentesque laoreet urna id arcu. * Pellentesque laoreet urna id arcu. * Aenean non erat et elit egestas dictum. * Aenean non erat et elit egestas dictum. * Proin ornare sem eget nulla. * Proin ornare sem eget nulla. * Phasellus placerat convallis elit. * Phasellus placerat convallis elit. * Donec ultricies metus non purus. * Donec ultricies metus non purus. * Sed vel enim et nunc accumsan egestas. * Sed vel enim et nunc accumsan egestas. * Cras eget elit in purus luctus ornare. * Cras eget elit in purus luctus ornare. * In pharetra ligula sodales pede. < * Morbi consectetuer mi vitae sem. * Morbi consectetuer mi vitae sem. * Donec sollicitudin pretium erat. * Donec sollicitudin pretium erat. * Cras facilisis nunc sed leo. * Cras facilisis nunc sed leo. * Nunc varius ante sed nisi. * Nunc varius ante sed nisi. > THIS SHOULDN'T BE HERE > THIS SHOULDN'T EITHER! * Aenean in quam sagittis est ornare ultricies. * Aenean in quam sagittis est ornare ultricies. * Etiam dignissim scelerisque velit. * Etiam dignissim scelerisque velit. * Mauris porta fringilla sapien. * Mauris porta fringilla sapien. * Proin vitae nisl vitae mauris viverra tempor. * Proin vitae nisl vitae mauris viverra tempor. * Maecenas quis arcu sed lorem mollis bibendum. * Maecenas quis arcu sed lorem mollis bibendum. * Morbi sed turpis non risus molestie posuere. | * Morbi sed non risus molestie posuere. * Curabitur id magna in nulla commodo tristique. * Curabitur id magna in nulla commodo tristique. * Praesent quis nulla vel augue faucibus viverra. | * Praesent quis nulla BAD vel augue faucibus viverra. * Sed interdum libero. | * Sed lacinia interdum libero. > ANOTHER ADDITION * Donec ultricies posuere arcu. * Donec ultricies posuere arcu. * Etiam interdum auctor mi. * Etiam interdum auctor mi.
The solution is to set a context size (-U argument) which is larger than the file itself:
diff -U 1000000 file1.txt file2.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With