25. Bash Shell - Text Processing: uniq, comm

The opening words

With Linux we can provide uniq, commto come and go heavy or compare the contents of the file command.
 

Non-reproducible results

We uniqprepare 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

Prepare some non-repeat and duplicate content
By default, uniqthe command output does not contain duplicate what follows:

uniq uniq_file.txt

The output of all but not duplicate content 

Duplicate Content

We can add -dor --repeatedparameters to duplicate the contents of the output file:

uniq -d uniq_file.txt
uniq --repeated uniq_file.txt

Uniq_file.txt duplicate content output file
 

Non-duplicate content

We can add -uor --uniqueparameters to the output files, non-duplicate content:

uniq -u uniq_file.txt
uniq --unique uniq_file.txt

Non-duplicate content output file uniq_file.txt
 

Case-insensitive duplicate content

We can add -dor --repeatedplus -ior --ignore-caseparameters are not case sensitive duplicate content output file:

uniq -d -i uniq_file.txt
uniq --repeated --ignore-case uniq_file.txt

Not case-sensitive file duplicate content output uniq_file.txt
 

Output content as well as its number of occurrences

We can add -cor --countparameters to output the contents of the file and repeat occurrences:

uniq -c uniq_file.txt
uniq --count uniq_file.txt

Uniq_file.txt output file contents and the number of occurrences
 

compare results

We need to create two files to demonstrate commcommand:

printf '%s\n' a b c d e     > file1
printf '%s\n'   b c d e f g > file2
cat file1
cat file2

To print the contents of file1 and 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

Compare file1 and file2 files
 

Hidden in the first column

We can use -1the parameters to hide the first column:

comm -1 file1 file2

Hidden in the first column
 

Hide the second column

We can use -2the parameters to hide the second column:

comm -2 file1 file2

Hide the second column
 

Hidden third column

We can use -3the parameters to hide the third column:

comm -3 file1 file2

Hidden third column
 

The first column shows

We can use -23parameters to display the first column:

comm -23 file1 file2

The first column shows
 

The second column shows

We can use -13parameters to display the second column:

comm -13 file1 file2

The second column shows
 

The third column display

We can use -12parameters to display the third column:

comm -12 file1 file2

The third column display
 

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 ."

Published 79 original articles · won praise 6 · views 1823

Guess you like

Origin blog.csdn.net/stevenchen1989/article/details/104079300