5. Comparing text
-
Let's create two test files:
cat > file1.txt <<EOF
a
b
c
d
EOFcat > file2.txt <<EOF
b
c
d
e
EOF -
We can compare them with
comm
:comm file1.txt file2.txt
comm -12 file1.txt file2.txt
In this case we are suppressing the columns 1 and 2.
-
A more complex tool is
diff
:diff file1.txt file2.txt
With context:
diff -c file1.txt file2.txt
Unified format is more concise:
diff -u file1.txt file2.txt
-
To create a patch file usually the options
-Naur
are used:diff -Naur file1.txt file2.txt > patchfile.txt
cat patchfile.txt
We can use the command
patch
to apply a patch file:patch file1.txt patchfile.txt
cat file1.txt
Now
file1.txt
has the same content asfile2.txt
.
Download lesson07/part5.cast
Loading asciinema cast...