Linux and Unix sdiff command
Compare two files side-by-side, optionally merge them interactively, and output the results.
sdiff [OPTION]... FILE1 FILE2
sdiff performs a side-by-side comparison of the differences between FILE1 and FILE2, and optionally merges them (see the -o option, below).
If one of the FILEs is specified as a dash ("-"), sdiff reads from standard input.
|-o FILE, --output=FILE||Merge the files interactively, and send the output to FILE. |
Specifying this option will begin the side-by-side comparison, and place you at a "%" prompt, asking you how to treat the differences. Press enter at the prompt to view the merging options, which are as follows:
When merging is complete, the merged contents will be written to FILE.
|-i, --ignore-case||Treat uppercase and lowercase letters as if they are the same.|
|-E, --ignore-tab-expansion||Ignore changes due to tab expansion (where tabs are expanded to blanks or spaces).|
|-b, --ignore-space-change||Ignore changes in the amount of white space (spaces, tabs, etc).|
|-W, --ignore-all-space||Ignore all white space.|
|-B, --ignore-blank-lines||Ignore changes whose lines are all blank.|
|-I RE, --ignore-matching-lines=RE||Ignore changes whose lines all match regular expression RE.|
|--strip-trailing-cr||Strip trailing carriage return on input.|
|-a, --text||Treat all files as text files.|
|-w NUM, --width=NUM||Output at most NUM (default 130) print columns.|
|-l, --left-column||Output only the left column of common lines.|
|-s, --suppress-common-lines||Do not output common lines.|
|-t, --expand-tabs||Oxpand tabs to spaces in output.|
|--tabsize=NUM||Set tab stops at every NUM (default 8) print columns.|
|-d, --minimal||Try hard to find a smaller set of changes.|
|-H, --speed-large-files||Assume large files (which contain many scattered, small changes).|
|--diff-program=PROGRAM||Use PROGRAM to compare files.|
|--help||Display a help message and exit.|
|-v, --version||Output version information and exit.|
Displaying Differences Side-By-Side
sdiff produces a side-by-side difference listing of the two files. The contents of the files are listed in two columns with a "gutter" between them. The gutter contains one of the following markers:
|white space||The corresponding lines are in common. That is, either the lines are identical, or the difference is ignored because of one of the --ignore options (see Handling White Space, below).|
||||The corresponding lines differ, and they are either both complete or both incomplete.|
|<||The files differ and only the first file contains the line.|
|>||The files differ and only the second file contains the line.|
|(||Only the first file contains the line, but the difference is ignored.|
|)||Only the second file contains the line, but the difference is ignored.|
|\||The corresponding lines differ, and only the first line is incomplete.|
|/||The corresponding lines differ, and only the second line is incomplete.|
Normally, an output line is incomplete if and only if the lines that it contains are incomplete. However, when an output line represents two differing lines, one might be incomplete while the other is not. In this case, the output line is complete, but its the gutter is marked "\" if the first line is incomplete, "/" if the second line is.
Side by side format is sometimes easiest to read, but it has limitations. It generates much wider output than usual, and truncates the display of any lines that are too long to fit. Also, it relies on lining up output more heavily than usual, so its output looks particularly bad if you use varying width fonts, nonstandard tab stops, or nonprinting characters.
The --ignore-tab-expansion (-E) option ignores the distinction between tabs and spaces on input. A tab is considered to be equivalent to the number of spaces to the next tab stop (see Tabs).
The --ignore-trailing-space (-Z) option ignores white space at line end.
The --ignore-space-change (-b) option is stronger than -E and -Z combined. It ignores white space at line end, and considers all other sequences of one or more white space characters within a line to be equivalent. With this option, sdiff considers the following two lines to be equivalent, where ‘$’ denotes the line end:
Here lyeth muche rychnesse in lytell space. -- John Heywood$ Here lyeth muche rychnesse in lytell space. -- John Heywood $
The --ignore-all-space (-w) option is stronger still. It ignores differences even if one line has white space where the other line has none. White space characters include tab, vertical tab, form feed, carriage return, and space; some locales may define additional characters to be white space. With this option, sdiff considers the following two lines to be equivalent, where ‘$’ denotes the line end and ‘^M’ denotes a carriage return:
Here lyeth muche rychnesse in lytell space.-- John Heywood$ He relyeth much erychnes seinly tells pace. --John Heywood ^M$
For many other programs the newline character is considered a white space character, but sdiff is a line-oriented program and a newline character always ends a line. Hence the -w or --ignore-all-space option does not ignore newline-related changes; it ignores only other white space changes.
sdiff myfile.txt myfile2.txt
Compares the files myfile.txt and myfile2.txt side-by-side, indicating their differences with a symbol in between them. Output will resemble the following:
The Way that can be told of is n < The name that can be named is no < The Nameless is the origin of He The Nameless is the origin of He The Named is the mother of all t | The named is the mother of all t > Therefore let there always be no Therefore let there always be no so we may see their subtlety, so we may see their subtlety, And let there always be being, And let there always be being, so we may see their outcome. so we may see their outcome. The two are the same, The two are the same, But after they are produced, But after they are produced, they have different names. they have different names. > They both may be called deep and > Deeper and more profound, > The door of all subtleties!