{"id":3237,"date":"2018-04-06T15:16:11","date_gmt":"2018-04-06T11:16:11","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-sdiff-command\/"},"modified":"2018-04-06T15:16:11","modified_gmt":"2018-04-06T11:16:11","slug":"linux-sdiff-command-tutorial-for-beginners-6-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-sdiff-command-tutorial-for-beginners-6-examples\/","title":{"rendered":"Linux sdiff Command Tutorial for Beginners (6 Examples)"},"content":{"rendered":"<p>Here at HowtoForge, we have already discussed\u00a0<a href=\"https:\/\/www.howtoforge.com\/tutorial\/linux-diff-command-options\/\" target=\"_blank\" rel=\"noopener noreferrer\">multiple<\/a> <a href=\"https:\/\/www.howtoforge.com\/tutorial\/how-to-compare-three-files-in-linux-using-diff3-tool\/\" target=\"_blank\" rel=\"noopener noreferrer\">command line utilities<\/a> that are focused on finding file differences. But there are several more such tools, and in this tutorial, we will discuss on such command dubbed <strong>sdiff\u00a0<\/strong>using some easy to understand examples.<\/p>\n<p>Please note that all examples mentioned in this article have been tested on Ubuntu 16.04 LTS.<\/p>\n<h2 id=\"linux-sdiff-command\">Linux sdiff command<\/h2>\n<p>The sdiff command shows you file differences in side-by-side form. Following is its syntax:<\/p>\n<p class=\"command\">sdiff [OPTION]&#8230; FILE1 FILE2<\/p>\n<p>And here&#8217;s how the man page describes it:<\/p>\n<pre>sdiff - side-by-side merge of file differences<br\/>Side-by-side merge of differences between FILE1 and FILE2.<\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how this tool works.<\/p>\n<h2 id=\"q-how-sdiff-command-works\">Q1. How sdiff command works?<\/h2>\n<p>Basic usage is simple, all you have to do is to run the sdiff command with filenames as arguments. For example:<\/p>\n<p class=\"command\">sdiff file1 file2<\/p>\n<p>file1 and file2 were exactly same in my case.<\/p>\n<p><a class=\"fancybox\" id=\"img-sdiff-file1-file2-same\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/sdiff-file1-file2-same.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples.png\" alt=\"How sdiff command works\" width=\"235\" height=\"340\" title=\"\"><\/a><\/p>\n<p>And here&#8217;s the output sdiff produced in this case:<\/p>\n<p><a class=\"fancybox\" id=\"img-sdiff-basic-output\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/sdiff-basic-output.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-1.png\" alt=\"sdiff command result\" width=\"500\" height=\"145\" title=\"\"><\/a><\/p>\n<p>This type of output means there&#8217;s no difference in files.<\/p>\n<h2 id=\"q-how-to-make-sdiff-ignore-case\">Q2. How to make sdiff ignore case?<\/h2>\n<p>Suppose file1 and file2 contain following lines:<\/p>\n<p><a class=\"fancybox\" id=\"img-sdiff-file1-file2-case\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/sdiff-file1-file2-case.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-2.png\" alt=\"How to make sdiff ignore case\" width=\"240\" height=\"339\" title=\"\"><\/a><\/p>\n<p>The command:<\/p>\n<p class=\"command\">sdiff file1 file2<\/p>\n<p>produces the following output:<\/p>\n<p><a class=\"fancybox\" id=\"img-sdiff-file1-file2-case-differ\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/sdiff-file1-file2-case-differ.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-3.png\" alt=\"sdiff file1 file2\" width=\"500\" height=\"140\" title=\"\"><\/a><\/p>\n<p>The pipe (|) in the first line in the second column indicates the two files are different in the very first line itself. However, if you want, you can force sdiff to ignore case, something which you can do using the -i command line option.<\/p>\n<p class=\"command\">sdiff -i file1 file2<\/p>\n<p><a class=\"fancybox\" id=\"img-sdiff-i-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/sdiff-i-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-4.png\" alt=\"sdiff -i file1 file2\" width=\"500\" height=\"141\" title=\"\"><\/a><\/p>\n<p>So you can see the output now shows the two files to be identical, meaning the case difference was ignored.<\/p>\n<h2 id=\"q-how-to-make-sdiff-ignore-spaces\">Q3. How to make sdiff ignore spaces?<\/h2>\n<p>In case any of the file contains spaces, the sdiff command will show the difference by default. However, if you want, you can suppress this behavior using the -Z command line option:<\/p>\n<p><a class=\"fancybox\" id=\"img-sdiff-z-option1\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/sdiff-z-option1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-5.png\" alt=\"How to make sdiff ignore spaces\" width=\"500\" height=\"287\" title=\"\"><\/a><\/p>\n<p>Then there are several other space-related options that you should be aware of. Here&#8217;s a list:<\/p>\n<pre>-E, --ignore-tab-expansion<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ignore changes due to tab expansion<\/pre>\n<pre>-b, --ignore-space-change<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ignore changes in the amount of white space<\/pre>\n<pre>-W, --ignore-all-space<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ignore all white space<\/pre>\n<h2 id=\"q-how-to-make-sdiff-ignore-blank-lines\">Q4. How to make sdiff ignore blank lines?<\/h2>\n<p>Just like spaces, by default, the sdiff command takes blank lines in to account as well. For example:<\/p>\n<p><a class=\"fancybox\" id=\"img-sdiff-blank-lines\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/sdiff-blank-lines.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-6.png\" alt=\"How to make sdiff ignore blank lines\" width=\"500\" height=\"160\" title=\"\"><\/a><\/p>\n<p>However, you can make the command ignore blank lines by using the -B command line option.<\/p>\n<p class=\"command\">sdiff -B file1 file2<\/p>\n<p><a class=\"fancybox\" id=\"img-sdiff-b-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/sdiff-b-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-7.png\" alt=\"sdiff -B file1 file2\" width=\"500\" height=\"160\" title=\"\"><\/a><\/p>\n<p>So you can see the sdiff command didn&#8217;t consider blank line as a difference in this case.<\/p>\n<h2 id=\"q-how-to-make-sdiff-suppress-common-lines\">Q5. How to make sdiff suppress common lines?<\/h2>\n<p>Suppose the files contain some common lines, and you want the sdiff command to suppress common lines, then you can do this using the -s command line option.<\/p>\n<p class=\"command\">sdiff -s file1 file2<\/p>\n<h2 id=\"q-how-to-make-sdiff-use-a-different-diff-program\">Q6. How to make sdiff use a different diff program?<\/h2>\n<p>By default, sdiff uses diff to carry out the comparison. However, if you want, you can even replace diff with the program of your choice. To do this, use the &#8211;diff-program option which requires program name as input.<\/p>\n<p class=\"command\">sdiff &#8211;diff-program=[PROGRAM] file1 file2<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The Sdiff tool might offer a lot of features, but it&#8217;s learning curve isn&#8217;t that steep. All you need to do is a bit of practice, and you should be good to go. We&#8217;ve discussed the majority of command line options here. For more, head to <a href=\"https:\/\/linux.die.net\/man\/1\/sdiff\" target=\"_blank\" rel=\"noopener noreferrer\">sdiff&#8217;s man page<\/a>.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-sdiff-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-8.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-sdiff-command%2F&amp;text=Linux+sdiff+Command+Tutorial+for+Beginners+%286+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-9.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-10.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-sdiff-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/04\/linux-sdiff-command-tutorial-for-beginners-6-examples-11.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Here at HowtoForge, we have already discussed\u00a0multiple command line utilities that are focused on finding file differences. But there are several more such tools, and in this tutorial, we will discuss on such command dubbed sdiff\u00a0using some easy to understand examples. Please note that all examples mentioned in this article have been tested on Ubuntu &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-3237","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=3237"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3237\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=3237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=3237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=3237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}