find-changelog-duplicates.sh (930B)
1 #!/bin/bash 2 3 # Usage function to display help 4 function usage() { 5 echo "Usage: $0 <file1> <file2>" 6 echo "Where:" 7 echo " <file1> is the file to find duplicates within" 8 echo " <file2> is the file to check these duplicates against" 9 echo 10 echo "This script finds duplicate lines in <file1> and prints out any" 11 echo "of these duplicates that exist in <file2>." 12 exit 1 13 } 14 15 # Check for help flag 16 if [[ "$1" == "-h" || "$1" == "--help" ]]; then 17 usage 18 fi 19 20 # Check the number of arguments provided 21 if [ "$#" -ne 2 ]; then 22 echo "Error: Two arguments are required." 23 usage 24 fi 25 26 # Assign arguments to variables 27 file1=$1 28 file2=$2 29 30 # Check if files exist 31 if [ ! -f "$file1" ]; then 32 echo "Error: File '$file1' does not exist." 33 exit 1 34 fi 35 36 if [ ! -f "$file2" ]; then 37 echo "Error: File '$file2' does not exist." 38 exit 1 39 fi 40 41 # Find duplicates and check against the second file 42 sort "$file1" | uniq -d | grep -Fxf - "$file2"