{"id":13290,"date":"2019-04-01T11:28:12","date_gmt":"2019-04-01T11:28:12","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13290"},"modified":"2019-04-01T11:28:12","modified_gmt":"2019-04-01T11:28:12","slug":"linux-sdiff-command-examples-for-linux-newbies","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/linux-sdiff-command-examples-for-linux-newbies\/","title":{"rendered":"Linux sdiff Command Examples for Linux Newbies"},"content":{"rendered":"<p>In one of our earlier article, we have explained about\u00a0<a href=\"https:\/\/www.tecmint.com\/best-linux-file-diff-tools-comparison\/\" target=\"_blank\" rel=\"noopener\">9 best file comparison and difference (Diff) tools<\/a>\u00a0for Linux systems. We listed a mixture of command-line and GUI tools for comparing and finding differences between files, each with certain remarkable features. Another useful diff utility for Linux is called\u00a0<strong>sdiff<\/strong>.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/compare-find-difference-between-two-directories-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Find Difference Between Two Directories Using Diff and Meld Tools<\/a><\/p>\n<p><strong>sdiff<\/strong>\u00a0is a simple command line utility for showing the differences between two files and merge interactively. It is easy to use and comes with straightforward usage options as explained below.<\/p>\n<p>The syntax for using\u00a0<strong>sdiff<\/strong>\u00a0is as follows.<\/p>\n<pre>$ sdiff option... file1 file2\r\n<\/pre>\n<h3>Show Difference Between Two Files in Linux<\/h3>\n<p><strong>1.<\/strong>\u00a0The easiest way to run\u00a0<strong>sdiff<\/strong>\u00a0is to provide the two filenames you are trying to compare. It will show the merged difference side-by-side as shown in the following screenshot.<\/p>\n<pre>$ cal &gt;cal.txt\r\n$ df -h &gt;du.txt\r\n$ sdiff du.txt cal.txt\r\n<\/pre>\n<div id=\"attachment_29107\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/04\/Check-Difference-Between-Files-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29107\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/04\/Check-Difference-Between-Files-in-Linux.png\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/04\/Check-Difference-Between-Files-in-Linux.png 862w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/04\/Check-Difference-Between-Files-in-Linux-768x323.png 768w\" alt=\"Check Difference Between Files in Linux\" width=\"862\" height=\"363\" aria-describedby=\"caption-attachment-29107\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-29107\" class=\"wp-caption-text\">Check Difference Between Files in Linux<\/p>\n<\/div>\n<h3>Treat all Files as Text Files<\/h3>\n<p><strong>2.<\/strong>\u00a0To treat all files as text and compare them line-by-line, whether they are text files or not, use the\u00a0<code>-a<\/code>\u00a0flag.<\/p>\n<pre><strong>$ sdiff -a du.txt cal.txt<\/strong>\r\n\r\nFilesystem      Size  Used Avail Use% Mounted on\t      |\t     April 2018       \r\nudev            3.9G     0  3.9G   0% \/dev\t\t      |\tSu Mo Tu We Th Fr Sa  \r\ntmpfs           788M  9.7M  779M   2% \/run\t\t      |\t 1  2  3  4  5  6  7  \r\n\/dev\/sda10      324G  265G   43G  87% \/\t\t\t      |\t 8  9 10 11 12 13 14  \r\ntmpfs           3.9G  274M  3.6G   7% \/dev\/shm\t\t      |\t15 16 17 18 19 20 21  \r\ntmpfs           5.0M  4.0K  5.0M   1% \/run\/lock\t\t      |\t22 23 24 25 26 27 28  \r\ntmpfs           3.9G     0  3.9G   0% \/sys\/fs\/cgroup\t      |\t29 30                 \r\n\/dev\/loop2       82M   82M     0 100% \/snap\/core\/4206\t      |\t                      \r\n\/dev\/loop4      181M  181M     0 100% \/snap\/vlc\/190\t      &lt;\r\n\/dev\/loop1       87M   87M     0 100% \/snap\/core\/4407\t      &lt;\r\n\/dev\/loop0      189M  189M     0 100% \/snap\/vlc\/158\t      &lt;\r\n\/dev\/loop3       83M   83M     0 100% \/snap\/core\/4327\t      &lt;\r\ncgmfs           100K     0  100K   0% \/run\/cgmanager\/fs\t      &lt;\r\ntmpfs           788M   40K  788M   1% \/run\/user\/1000\t      &lt;\r\n<\/pre>\n<h3>Ignore Tabs and White Space<\/h3>\n<p><strong>3.<\/strong>\u00a0If you have files with too much whitespace, you can tell\u00a0<strong>sdiff<\/strong>\u00a0to ignore all white space while comparing using the\u00a0<code>-W<\/code>\u00a0switch.<\/p>\n<pre><strong>$ sdiff -W du.txt cal.txt<\/strong>\r\n<\/pre>\n<p><strong>4.<\/strong>\u00a0You can also tell\u00a0<strong>sdiff<\/strong>\u00a0to ignore any white space at line end using the\u00a0<code>-z<\/code>\u00a0option.<\/p>\n<pre>$ sdiff -z du.txt cal.txt\r\n<\/pre>\n<p><strong>5.<\/strong>\u00a0In addition, you can instruct\u00a0<strong>sdiff<\/strong>\u00a0to ignore changes due to tab expansion with the\u00a0<code>-E<\/code>\u00a0flag.<\/p>\n<pre>$ sdiff -E du.txt cal.txt\r\n<\/pre>\n<h3>Ignore Case While Comparing Difference<\/h3>\n<p><strong>6.<\/strong>\u00a0To ignore case (where\u00a0<strong>sdiff<\/strong>\u00a0treats upper- and lower-case as the same), use the\u00a0<code>-i<\/code>\u00a0option as shown.<\/p>\n<pre>$ sdiff -i du.txt cal.txt\r\n<\/pre>\n<h3>Ignore Blank Lines While Comparing Difference<\/h3>\n<p><strong>7.<\/strong>\u00a0The\u00a0<code>-B<\/code>\u00a0option helps to ignore blank line in files.<\/p>\n<pre>$ sdiff -B du.txt cal.txt\r\n<\/pre>\n<h3>Define Number of Columns to Output<\/h3>\n<p><strong>8.<\/strong>\u00a0<strong>sdiff<\/strong>\u00a0allows you to set the number of columns to be printed (default is\u00a0<strong>130<\/strong>), by using the\u00a0<code>-w<\/code>\u00a0switch as follows.<\/p>\n<pre>$ sdiff -w 150 du.txt cal.txt\r\n<\/pre>\n<h3>Expand Tabs to Spaces<\/h3>\n<p><strong>9.<\/strong>\u00a0To expand tabs to spaces in output, use the\u00a0<code>-t<\/code>\u00a0option.<\/p>\n<pre>$ sdiff -t du.txt cal.txt\r\n<\/pre>\n<h3>Run sdiff Interactively<\/h3>\n<p><strong>10.<\/strong>\u00a0The\u00a0<code>-o<\/code>\u00a0flag enables it to run more interactively and send output to a file. In this command, the output will be sent to the\u00a0<strong>sdiff.txt<\/strong>\u00a0file, press\u00a0<strong>Enter<\/strong>\u00a0after seeing the\u00a0<code>%<\/code>\u00a0sign, to get the interactive menu.<\/p>\n<pre><strong>$ sdiff du.txt cal.txt -o sdiff.txt<\/strong>\r\n\r\nFilesystem      Size  Used Avail Use% Mounted on\t      |\t     April 2018       \r\nudev            3.9G     0  3.9G   0% \/dev\t\t      |\tSu Mo Tu We Th Fr Sa  \r\ntmpfs           788M  9.7M  779M   2% \/run\t\t      |\t 1  2  3  4  5  6  7  \r\n\/dev\/sda10      324G  265G   43G  87% \/\t\t\t      |\t 8  9 10 11 12 13 14  \r\ntmpfs           3.9G  274M  3.6G   7% \/dev\/shm\t\t      |\t15 16 17 18 19 20 21  \r\ntmpfs           5.0M  4.0K  5.0M   1% \/run\/lock\t\t      |\t22 23 24 25 26 27 28  \r\ntmpfs           3.9G     0  3.9G   0% \/sys\/fs\/cgroup\t      |\t29 30                 \r\n\/dev\/loop2       82M   82M     0 100% \/snap\/core\/4206\t      |\t                      \r\n\/dev\/loop4      181M  181M     0 100% \/snap\/vlc\/190\t      &lt;\r\n\/dev\/loop1       87M   87M     0 100% \/snap\/core\/4407\t      &lt;\r\n\/dev\/loop0      189M  189M     0 100% \/snap\/vlc\/158\t      &lt;\r\n\/dev\/loop3       83M   83M     0 100% \/snap\/core\/4327\t      &lt;\r\ncgmfs           100K     0  100K   0% \/run\/cgmanager\/fs\t      &lt;\r\ntmpfs           788M   40K  788M   1% \/run\/user\/1000\t      &lt;\r\n<code>%<\/code> ed: Edit then use both versions, each decorated with a header. eb: Edit then use both versions. el or e1: Edit then use the left version. er or e2: Edit then use the right version. e: Discard both versions then edit a new one. l or 1: Use the left version. r or 2: Use the right version. s: Silently include common lines. v: Verbosely include common lines. q: Quit. %<\/pre>\n<p>Note that you need to have some of the editors such as\u00a0<strong>ed<\/strong>\u00a0installed on your system before using them, in this scenario.<\/p>\n<h3>Invoke Another Program To Compare Files<\/h3>\n<p><strong>11.<\/strong>\u00a0The\u00a0<code>--diff-program<\/code>\u00a0switch allows you to call another command-line tool, other than\u00a0<strong>sdiff<\/strong>\u00a0itself to compare files, for instance, you can call the\u00a0<strong>diff<\/strong>\u00a0program as shown.<\/p>\n<pre>$ sdiff --diff-program=diff du.txt cal.txt\r\n<\/pre>\n<p>For more information, consult the sdiff man page.<\/p>\n<pre>$ man sdiff\r\n<\/pre>\n<p>In this article, we looked at\u00a0<strong>sdiff<\/strong>\u00a0command-line tool examples for beginners. If you have any questions, use the comment form below to reach us.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-sdiff-command-examples\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of our earlier article, we have explained about\u00a09 best file comparison and difference (Diff) tools\u00a0for Linux systems. We listed a mixture of command-line and GUI tools for comparing and finding differences between files, each with certain remarkable features. Another useful diff utility for Linux is called\u00a0sdiff. Read Also:\u00a0How to Find Difference Between Two &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/linux-sdiff-command-examples-for-linux-newbies\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Linux sdiff Command Examples for Linux Newbies&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13290","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13290"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13290\/revisions"}],"predecessor-version":[{"id":13291,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13290\/revisions\/13291"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}