Home > Text Processing & Search > sdiff

sdiff: Compare Two Files Side-by-Side

The sdiff command compares two files in parallel, outputting their differences side-by-side in two columns for easy visual inspection. Unlike the `diff` command, it clearly distinguishes common and differing parts visually.

Overview

sdiff, short for `side-by-side diff`, compares the contents of two files by displaying them next to each other. Identical lines are indicated by spaces in the middle, while differing lines are marked with specific symbols (e.g., `|`, `<`, `>`). This method is very useful for intuitively understanding what has been added, deleted, or modified during code reviews or configuration file comparisons.

Key Features

Key features of the sdiff command include:

  • Compares two files by outputting them side-by-side.
  • Uses clear symbols (`|`, `<`, `>`) to indicate differences.
  • Suitable for human visual comparison of results, not for scripting.
  • Facilitates quick understanding of changes in text files.

sdiff Output Symbols

sdiff uses specific symbols to indicate the relationship between lines in files.

  • |: The corresponding lines in both files are different.
  • <: The line exists only in the left file (first file).
  • >: The line exists only in the right file (second file).
  • (space): The corresponding lines in both files are identical.

Key Options

Commonly used sdiff command options are grouped by purpose.

1) Comparison Options

2) Help

Generated command:

Try combining the commands.

Description:

`sdiff` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn the functionality of the sdiff command through various usage examples.

Compare Two Files Side-by-Side

sdiff file1.txt file2.txt

Compares and outputs the contents of two files side-by-side. `|` indicates a change, `<` indicates a line only in the left file, and `>` indicates a line only in the right file.

Compare Hiding Identical Lines

sdiff -s file1.txt file2.txt

Uses the `-s` option to hide identical lines and output only the differences.

Specify Output Width

sdiff -w 100 file1.txt file2.txt

Uses the `-w` option to specify an output width of 100 characters.

Interactive Merge

sdiff -o merged.txt file1.txt file2.txt

Uses the `-o` option to output to `merged.txt` and proceeds with an interactive merge operation when differences are found.

Installation

sdiff is typically included by default as part of the `diffutils` package in most Linux distributions. No separate installation is usually required.

Tips & Cautions

Here are some points to keep in mind when using the sdiff command.

Tips

  • `sdiff` is primarily used by humans for direct file comparison and checking changes.
  • If the output is complex, it is convenient to use `sdiff` results with a pager like `less` or `more`.
  • When using the `-o` option for interactive merging, you can use commands such as `l` (left), `r` (right), `e` (edit manually), `s` (skip), `q` (quit).

Related commands

These are commands that are functionally similar or are commonly used together.


Same category commands