There are two files called “file1.txt"
and “file2.txt" both have a list of words. Now we want to
check which words are extra in "file1.txt" and are
not in "file2.txt"
Diff analyzes two files and prints the lines that are
different. Essentially, it outputs a set of instructions for how to change one file in order to make it
identical to the second file.
Comparing
the content of files using:
- diff file1 file2 - Compare two files
- colordiff file1 file2 - Same as diff output with color and syntax highlight
- sdiff file1 file2 - Side-by-Side comparison
- vimdiff file1 file2 - Highlighted difference in vim
- wdiff file1 file2 - Compare files word by word
Files we are going to compare:
cat file.txt
cat file2.txt
diff
command output:
diff file.txt file2.txt
1c1 -
Line no. of file 1 – Action -
Line no. of file 2
Action:- a - Add, c – Change, d – Delete, < - Line from
file1, > - Line from file2
Result:-
- 1c1 - file.txt line no. 1 changed in file2.txt
- 6d5 - file.txt line no. 6 deleted in file2.txt
- 11c10 - file.txt line no. 11 changed in files2.txt
apt-get install colordiff (for
installing colordiff)
colodiff file.txt
file2.txt
Same as diff output with color and syntax highligtht
sdiff command output:
sdiff file.txt
file2.txt
Actions:-
| - Differing lines
< - Line in file1 but not in
file2
> - Line in file2 but not in
file1
vimdiff command output:
vimdiff file.txt file2.txt
- Ctrl+w w - Goto next window
- :q - Quit (close) current window
- :qa - Quit all
- :qa! - Force quit all
apt-get install wdiff (for install wdiff)
wdiff fle.txt file2.txt
Actions:- It covers the removed word / line with [- -]
- It covers the added word / line with {+ +}
Comparing Files in Linux
Reviewed by vijay pratap singh
on
March 27, 2017
Rating:
No comments: