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.txtcomm -12 file1.txt file2.txtIn this case we are suppressing the columns 1 and 2.
-
A more complex tool is
diff:diff file1.txt file2.txtWith context:
diff -c file1.txt file2.txtUnified format is more concise:
diff -u file1.txt file2.txt -
To create a patch file usually the options
-Naurare used:diff -Naur file1.txt file2.txt > patchfile.txtcat patchfile.txtWe can use the command
patchto apply a patch file:patch file1.txt patchfile.txtcat file1.txtNow
file1.txthas the same content asfile2.txt.
Download lesson07/part5.cast
Loading asciinema cast...