Linux Diff Command Tutorial with Examples To Compare Two Text File

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-diff-command-tutorial-with-examples-to-compare-two-text-file/
PINTEREST
PINTEREST
INSTAGRAM

Comparing files line by line can be done with tool named diff. There are a lot of different options provided by diff. We will look most popular and useful features in this tutorial.

Syntax

diff have simple syntax. There are options which we will look later and files to be compared.

Compare Two Files

In this example we will compare two files line by line

If there is no output after diff operation this means that there is no difference between files.

In this output we see that one line is different. > means second file have one extra line

  • 3a4 means after line 3 line 4 is added

We change file and compare again with the same command

file1

file2

  • 3d2 Lines 3 in the file1 need to be deleted in order to match line 2 in the file2
  • 4a4 From file2 delete line 4 to match first file line 4

View Verbose Diff

We can list all lines of two files with which lines will added or deleted both files to match each other.

Unified Mode

In unified view only one file is shown with related changes like delete or add. It is simpler than verbose mode to review.

LEARN MORE  How Convert Files Between Ascii and Utf-8

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-diff-command-tutorial-with-examples-to-compare-two-text-file/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.