FactorPad
Build a Better Process

Linux sdiff Command Summary with Examples

Linux sdiff allows you to compare and merge two files.
  1. Purpose - Learn what sdiff is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with sdiff.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux sdiff, 36 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / sdiff-command.html


An ad-free and cookie-free website.


The Linux sdiff Command

Beginner

Learn to compare and merge two files at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux sdiff Command Summary with Examples (3:48)

Video Script

The Command and Why You Need It

Our thirty-sixth word, or command to memorize is sdiff from our category Text.

sdiff allows you to compare and merge two files.

Common Linux sdiff Options
-options description
--help Print help screen
-o, --output=FILE Operate interactively and send output to FILE

Recall from diff and comm videos before this, we're reviewing files comparison alternatives, and now sdiff adds the functionality to merge files.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The sdiff command has 20 options, and the arguments are the two files you'd like to compare and merge.

Like most commands, help is available with double-dash --help. The options here are not quite as advanced as with diff, but more extensive than comm.

The one option I'd like to draw your attention to here is -o which offers the ability to interactively merge files.

So why is sdiff an important command? Well, you might want to debug changes to code. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's first take a quick look at files we've been comparing for this, now our third example of comparison commands.

$ ls stuff video16.txt video21.txt video26.txt video32.txt video35.txt video05.txt video19.txt video23.txt video27.txt video33.txt video11.txt video20.txt video24.txt video31.txt video34.txt

We can use sdiff without options, and the first argument is video34.txt and it had an incorrect date if you recall, and then video35.txt is the corrected version.

$ sdiff video34.txt video35.txt Oct 4:video05.txt Oct 4:video05.txt Oct 10:video11.txt Oct 10:video11.txt Oct 9:video16.txt | Oct 10:video16.txt Oct 12:video19.txt Oct 12:video19.txt Oct 12:video20.txt Oct 12:video20.txt Oct 13:video21.txt Oct 13:video21.txt Oct 13:video23.txt Oct 13:video23.txt Oct 15:video24.txt Oct 14:video24.txt Oct 15:video26.txt Oct 15:video26.txt Oct 15:video27.txt Oct 15:video27.txt Oct 17:video31.txt Oct 17:video31.txt Oct 18:video32.txt Oct 18:video32.txt Oct 18:video33.txt Oct 18:video33.txt $ clear

Next, let's use the sdiff with the -o option, give it a file name video36.txt, then our two arguments from before.

$ sdiff -o video36.txt video34.txt video35.txt Oct 4:video05.txt Oct 4:video05.txt Oct 10:video11.txt Oct 10:video11.txt Oct 9:video16.txt | Oct 10:video16.txt %r Oct 12:video19.txt Oct 12:video19.txt Oct 12:video20.txt Oct 12:video20.txt Oct 13:video21.txt Oct 13:video21.txt Oct 13:video23.txt Oct 13:video23.txt Oct 15:video24.txt Oct 14:video24.txt Oct 15:video26.txt Oct 15:video26.txt Oct 15:video27.txt Oct 15:video27.txt Oct 17:video31.txt Oct 17:video31.txt Oct 18:video32.txt Oct 18:video32.txt Oct 18:video33.txt Oct 18:video33.txt

Interactively, means it will prompt you with this % symbol and here I'll use r for the file on the right, but I could pick a line on the left if I wanted.

And last, let's do a quick cat of the new video36.txt to verify.

$ cat video36.txt Oct 4:video05.txt Oct 10:video11.txt Oct 10:video16.txt Oct 12:video19.txt Oct 12:video20.txt Oct 13:video21.txt Oct 13:video23.txt Oct 15:video24.txt Oct 15:video26.txt Oct 15:video27.txt Oct 17:video31.txt Oct 18:video32.txt Oct 18:video33.txt

A Final Tip

Okay now you know how to use sdiff. And you know the syntax for commands, options and arguments.

One last tip about the sdiff command. So sdiff provides you with a third command to compare files, I suggest studying up and then picking your favorite.

Okay, thanks for visiting today. I hope this was a helpful introduction to the sdiff command.


Learn More About The Series

For an overview 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

If you learned something please consider subscribing to our YouTube Channel. Plus, you'll be notified of new content.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / sdiff-command.html


linux sdiff command
sdiff linux
linux sdiff
unix sdiff
sdiff unix
linux sdiff examples
sdiff files
sdiff command
linux compare two files
linux merge files
linux compare files
sdiff command syntax
sdiff compare files
sdiff summary
man sdiff
sdiff options
sdiff linux tutorial

A newly-updated free resource. Connect and refer a friend today.