Open In App

sdiff command in Linux with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

sdiff command in linux is used to compare two files and then writes the results to standard output in a side-by-side format. It displays each line of the two files with a series of spaces between them if the lines are identical. It displays greater than sign if the line only exists in the file specified by the File2 parameter, and a | (vertical bar) for lines that are different.

Syntax:

sdiff [  -l | -s ] [  -o OutFile ] [  -w Number ] File1 File2

Example:
Text File 1:

Geeks
For 
Geeks

A 
Computer
Science
Portal
For
Geeks

Text File 2:

Geeks
For 
Geeks

Technical
Scripter
2018

Options of sdiff command:

  • sdiff -l file1 file2 : It displays only the left side when lines are identical.
  • sdiff -s file1 file2 : It does not display the identical identical lines.
  • sdiff -w Number file1 file2 : It sets the width of the output line. The default value of the Number variable is 130 characters. The maximum width of the Number variable is 2048. The minimum width of the Number variable is 20. The sdiff command uses 2048 if a value greater than 2048 is specified.
  • sdiff -o OutFile file1 file2 : Creates a third file, specified by the OutFile variable, by a controlled line-by-line merging of the two files specified by the File1 and the File2 parameters. The following subcommands govern the creation of this file:

    Output File:

    Geeks
    For 
    Geeks
    
    --- geek1.txt 5, 10
    A 
    Computer
    Science
    Portal
    For
    Geeks
    +++ geek2.txt 5, 8
    Technical
    Scripter
    2018
    

Reference: https://www.tecmint.com/linux-sdiff-command-examples/


Last Updated : 27 May, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads