/ factorpad.com / tech / linux-essentials / sdiff-command.html
An ad-free and cookie-free website.
Beginner
Learn to compare and merge two files at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux sdiff Command Summary with Examples (3:48)
Our thirty-sixth word, or command to memorize is
sdiff
from our category
Text.
sdiff
allows you to compare and
merge two files.
-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.
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.
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.
Next, let's use the sdiff
with the
-o
option, give it a file name
video36.txt
, then our two arguments
from before.
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.
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.
For an overview 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
If you learned something please consider subscribing to our YouTube Channel. Plus, you'll be notified of new content.
comm
command,
hit Back.paste
command, click Next./ factorpad.com / tech / linux-essentials / sdiff-command.html
A newly-updated free resource. Connect and refer a friend today.