compare_manifest.sh
· 1.0 KiB · Bash
Surowy
#!/usr/bin/env bash
# compare_manifest.sh - Compare two manifest files and list packages present in the first but not the second.
set -euo pipefail
# Function to display usage information
usage() {
echo "Usage: $0 <left.manifest> <right.manifest>"
echo
echo "Extracts package names (first column) from each manifest, sorts them,"
echo "and prints packages present in the left file but not in the right."
exit 1
}
# Ensure exactly two arguments are provided
if [[ $# -ne 2 ]]; then
usage
fi
left_manifest="$1"
right_manifest="$2"
# Create a temporary directory for intermediate files
tmpdir=$(mktemp -d)
# Ensure the temporary directory is removed on script exit
trap 'rm -rf "${tmpdir}"' EXIT
# Extract package names (first column), sort, and write to temp files
awk '{print $1}' "${left_manifest}" | sort > "${tmpdir}/left.txt"
awk '{print $1}' "${right_manifest}" | sort > "${tmpdir}/right.txt"
# Output the comparison result
echo "Packages in '${left_manifest}' but not in '${right_manifest}':"
comm -23 "${tmpdir}/left.txt" "${tmpdir}/right.txt"
| 1 | #!/usr/bin/env bash |
| 2 | # compare_manifest.sh - Compare two manifest files and list packages present in the first but not the second. |
| 3 | |
| 4 | set -euo pipefail |
| 5 | |
| 6 | # Function to display usage information |
| 7 | usage() { |
| 8 | echo "Usage: $0 <left.manifest> <right.manifest>" |
| 9 | echo |
| 10 | echo "Extracts package names (first column) from each manifest, sorts them," |
| 11 | echo "and prints packages present in the left file but not in the right." |
| 12 | exit 1 |
| 13 | } |
| 14 | |
| 15 | # Ensure exactly two arguments are provided |
| 16 | if [[ $# -ne 2 ]]; then |
| 17 | usage |
| 18 | fi |
| 19 | |
| 20 | left_manifest="$1" |
| 21 | right_manifest="$2" |
| 22 | |
| 23 | # Create a temporary directory for intermediate files |
| 24 | tmpdir=$(mktemp -d) |
| 25 | # Ensure the temporary directory is removed on script exit |
| 26 | trap 'rm -rf "${tmpdir}"' EXIT |
| 27 | |
| 28 | # Extract package names (first column), sort, and write to temp files |
| 29 | awk '{print $1}' "${left_manifest}" | sort > "${tmpdir}/left.txt" |
| 30 | awk '{print $1}' "${right_manifest}" | sort > "${tmpdir}/right.txt" |
| 31 | |
| 32 | # Output the comparison result |
| 33 | echo "Packages in '${left_manifest}' but not in '${right_manifest}':" |
| 34 | comm -23 "${tmpdir}/left.txt" "${tmpdir}/right.txt" |
| 35 |