The opening words
With Linux we can provide uniq
, comm
to come and go heavy or compare the contents of the file command.
Non-reproducible results
We uniq
prepare some repetitive and non-repetitive content command:
echo 'I am duplicated' >> uniq_file.txt
echo 'I am duplicated' >> uniq_file.txt
echo 'I am duplicated' >> uniq_file.txt
echo 'I am Duplicated' >> uniq_file.txt
echo 'I am Duplicated' >> uniq_file.txt
echo 'I am Duplicated' >> uniq_file.txt
echo 'Line unique 1' >> uniq_file.txt
echo 'Line unique 2' >> uniq_file.txt
echo 'Line unique 3' >> uniq_file.txt
By default, uniq
the command output does not contain duplicate what follows:
uniq uniq_file.txt
Duplicate Content
We can add -d
or --repeated
parameters to duplicate the contents of the output file:
uniq -d uniq_file.txt
uniq --repeated uniq_file.txt
Non-duplicate content
We can add -u
or --unique
parameters to the output files, non-duplicate content:
uniq -u uniq_file.txt
uniq --unique uniq_file.txt
Case-insensitive duplicate content
We can add -d
or --repeated
plus -i
or --ignore-case
parameters are not case sensitive duplicate content output file:
uniq -d -i uniq_file.txt
uniq --repeated --ignore-case uniq_file.txt
Output content as well as its number of occurrences
We can add -c
or --count
parameters to output the contents of the file and repeat occurrences:
uniq -c uniq_file.txt
uniq --count uniq_file.txt
compare results
We need to create two files to demonstrate comm
command:
printf '%s\n' a b c d e > file1
printf '%s\n' b c d e f g > file2
cat file1
cat file2
By default, three COMM output data, the first column is the first file after the two files in the non-duplicate data comparison, the second column is the second in the file after the comparison non-repetitive data, the third column is two Comparative overlapping file after the data:
comm file1 file2
Hidden in the first column
We can use -1
the parameters to hide the first column:
comm -1 file1 file2
Hide the second column
We can use -2
the parameters to hide the second column:
comm -2 file1 file2
Hidden third column
We can use -3
the parameters to hide the third column:
comm -3 file1 file2
The first column shows
We can use -23
parameters to display the first column:
comm -23 file1 file2
The second column shows
We can use -13
parameters to display the second column:
comm -13 file1 file2
The third column display
We can use -12
parameters to display the third column:
comm -12 file1 file2
I wrote the English version
25. Bash Shell - Text Processing: uniq, comm
Quote
See also
Want to see the other contents of the manual? Visit the column belongs manual: " Linux Administrator's Guide: both simple and profound ."