bash only keep duplicate lines code example

Example 1: bash only print duplicated lines

# Basic syntax:
sort input_file | uniq -d
# Sort the file first because uniq requires a sorted file to work

# Note, uniq -d only prints one instance of lines that have duplicates
#	Use, uniq -c to count the number of duplicates in the file

Example 2: bash how to keep one instance of duplicate lines

# Basic syntax:
sort input_file | uniq
# Sort the file first because uniq requires a sorted file to work. Uniq
# then eliminates all duplicated lines in the file, keeping one instance
# of each duplicated line