sdif updated

Side-by-side / ANSI color / word context


Unicode / Japanese


With --mecab morphology



sdif - side-by-side diff viewer for ANSI terminal


sdif file_1 file_2

diff ... | sdif

--number, -n        print line number
--digit=n           set the line number digits (default 4)
--truncate, -t      truncate long line
--onword            fold line on word boundaries
--width, -w #       specify width of output (default is 80)
--diff=s            set diff command
--diffopts=s        set diff command options
--[no]color         use color or not
--colormap, --cm    specify color map
--mark=position     mark position (right, left, center, side) or no
--man               display manual page
-c, -C#             context diff
-u, -U#             unified diff

--cdif              use ``cdif'' as word context diff backend
--cdifopts          set cdif command options
--mecab             pass --mecab option to cdif


sdif is inspired by System V sdiff(1) command. The basic feature of sdif is making a side-by-side listing of two different files. All contents of two files are listed on left and right sides. Center column is used to indicate how different those lines. No mark means no difference. Added, deleted and modified lines are marked with `<' and `>' character.

1 deleted  <
2 same          1 same
3 changed  <>   2 modified
4 same          3 same
            >   4 added

It also reads and formats the output from diff command from standard input. Besides normal diff output, context diff -c and unified diff -u output will be handled properly.

Each lines can be displayed in different colors. Read --colormap section in ths manual for detail.

While sdif doesn't care about the contents of each modified lines, it can read the output from cdif command which show the word context differences of each lines. Option --cdif set the appropriate options for cdif. Set --nocc, --nomc options at least when invoking cdif manually. Option --notc is pereferable because text color can be handled by sdif.

Environment valuable SDIFOPTS is used to set default options.


  • --w=width, -w

    Use width as a width of output listing. Default width is 80. If the standard error is assinged to a terminal, the width is taken from it if possible.

  • --number, -n

    Print line number on each lines.

  • --digit=n

    Line number is diplayed in 4 digits by dafult. Use this option to change it.

  • -c, -Cn, -u, -Un

    Passed through to the back-end diff command. Sdif can interpret the output from normal, context (diff -c) and unified diff (diff -u).

  • --truncate, -t

    Truncate lines if they are longer than printing width.

  • --onword

    Fold longs line at word boundaries.

  • --cdif

    Use cdif command instead of normal diff command.

  • --cdifopts=option

    Specify options for backend cdif command.

  • --mecab

    Pass --mecab option to backend cdif command. Use --cdifopts to set other options.

  • --diff=command

    Any command can be specified as a diff command to be used. Piping output to sdif is easier unless you want to get whole text.

  • --diffopts=option

    Specify options for backend diff command.

  • --mark=position

    Specify the position for mark. Choose from left, right, center, side or no. Default is center.

  • --[no]color

    Use ANSI color escape sequence for output. Default is true.

  • --colormap=colormap, --cm=colormap

    Basic colormap format is :


    where the FIELD is one from these :

      OLD       NEW       UNCHANGED
      --------- --------- ---------
      OCOMMAND  NCOMMAND           : Command line
      OFILE     NFILE              : File name
      OMARK     NMARK     UMARK    : Mark
      OLINE     NLINE     ULINE    : Line number
      OTEXT     NTEXT     UTEXT    : Text

    You can make multiple filelds same color joining them by = :


    Also wildcard can be used for field name :


    Multiple fields can be specified by repeating options

      --cm FILED1=COLOR1 --cm FIELD2=COLOR2 ...

    or combined with comma (,) :

      --cm FILED1=COLOR1,FIELD2=COLOR2, ...

    COLOR is combination of single character representing uppercase foreground color :

      R  Red
      G  Green
      B  Blue
      C  Cyan
      M  Magenta
      Y  Yellow
      K  Black
      W  White

    and corresponding lowercase background color :

      r, g, b, c, m, y, k, w

    and other effects :

      S  Standout (reverse video)
      U  Underline
      D  Double-struck (boldface)
      F  Flash (blink)
      E  Expand

    E is effective for command, file and text line. That line will be expanded to window width filling up by space characters. Left column is expanded always. You may want to use this to set background color for right column.

    Defaults are :

      OCOMMAND => "CSE"
      NCOMMAND => "MSE"
      OFILE    => "CDE"
      NFILE    => "MDE"
      OMARK    => "Cw"
      NMARK    => "Mw"
      UMARK    => "w"
      OLINE    => "Y"
      NLINE    => "Y"
      ULINE    => "Y"
      OTEXT    => "C"
      NTEXT    => "M"
      UTEXT    => ""

    This is equivalent to :

           --cm 'OMARK=Cw,NMARK=Mw,UMARK=w' \
           --cm '*LINE=Y,OTEXT=C,NTEXT=M,UTEXT='

    Try next setting if you want to make modified section more visible.

      sdif -n --cdif --cm '[ON]TEXT=wE,UMARK=,OMARK=C,NMARK=M'


Kazumasa Utashiro


perl(1), diff(1), cdif(1)

cdif, sdif