Using 'diff' (or anything else) to get character-level diff between text files

前端 未结 15 2250
借酒劲吻你
借酒劲吻你 2020-12-02 05:40

I\'d like to use \'diff\' to get a both line difference between and character difference. For example, consider:

File 1

abcde
ab         


        
15条回答
  •  庸人自扰
    2020-12-02 06:26

    Most of these answers mention using of diff-highlight, a Perl module. But I didn't want to figure out how to install a Perl module. So I made a few minor changes to it to be a self-contained Perl script.

    You can install it using:

    ▶ curl -o /usr/local/bin/DiffHighlight.pl \
       https://raw.githubusercontent.com/alexharv074/scripts/master/DiffHighlight.pl
    

    And the usage (if you have the Ubuntu colordiff mentioned in zhanxw's answer):

    ▶ diff -u f1 f2 | colordiff | DiffHighlight.pl
    

    And the usage (if you don't):

    ▶ diff -u f1 f2 | DiffHighlight.pl
    

提交回复
热议问题