A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/sdiff-command-in-linux-with-examples/ below:

sdiff command in Linux with Examples

sdiff command in Linux with Examples

Last Updated : 27 Sep, 2024

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 a 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

where,

Basic Example

Text File 1 (file1.txt):

Geeks
For 
Geeks

A 
Computer
Science
Portal
For
Geeks

Text File 2 (file2.txt):

Geeks
For 
Geeks

Technical
Scripter
2018

Running the Command:

sdiff file1.txt file2.txt

Output:

Geeks                             Geeks
For                                   For
Geeks                              Geeks
                                          >
A                                       Technical
Computer                       Scripter
Science                           2018
Portal                               |
For                                    For
Geeks                               Geeks
Common Options used with the sdiff command 1. sdiff -l file1 file2:

Display only the left side of the comparison when lines are identical. This reduces the width of the output, making it easier to read.

2. sdiff -s file1 file2:

Suppress identical lines. This option only shows lines that are different between the two files, making it easier to focus on the differences.

3. 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.

4. 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
Conclusion

The sdiff command is an essential tool for file comparison in Linux, offering clear side-by-side output for identifying differences between two files. With options to suppress identical lines, set output width, and merge files interactively, it is highly customizable and versatile, making it suitable for a wide range of tasks, including software development, document comparison, and system administration.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4