gregj529

compare.sh

Oct 12th, 2023 (edited)
1,094
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.85 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Check if the correct number of arguments is provided
  4. if [ "$#" -ne 4 ]; then
  5.     echo "Usage: $0 <File1> <File2> <OutputFile1> <OutputFile2>"
  6.     exit 1
  7. fi
  8.  
  9. file1=$1
  10. file2=$2
  11. output1=$3
  12. output2=$4
  13.  
  14. # Function to compare values and generate output
  15. compare_and_output() {
  16.     while IFS=" " read -r id1 col1 _; do
  17.         IFS=" " read -r id2 col2 _
  18.         if [ "$col1" != "$col2" ]; then
  19.             echo "$id1 $col1 $col2" >> "$output1"
  20.             echo "$col1 $col2" >> "$output2"
  21.         fi
  22.     done < <(paste <(cut -d" " -f2,3 "$file1") <(cut -d" " -f2,3 "$file2"))
  23. }
  24.  
  25. # Compare values and generate output
  26. compare_and_output
  27.  
  28. # Count occurrences of each unique qualitative difference
  29. sort "$output2" | uniq -c > "$output2.tmp"
  30. mv "$output2.tmp" "$output2"
  31.  
  32. echo "Comparison completed. Results saved in $output1 and $output2."
Advertisement
Add Comment
Please, Sign In to add comment