-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompare
More file actions
executable file
·59 lines (50 loc) · 1.28 KB
/
compare
File metadata and controls
executable file
·59 lines (50 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
# Check if at least one argument is provided
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <file1.txt> <file2.txt> ..."
exit 1
fi
# Create an associative array to store file presence
declare -A file_presence
# Read each file and update the file presence array
for file in "$@"; do
while IFS= read -r line; do
file_presence["$line"]+="${file} "
done < "$file"
done
# Get the list of all unique files
unique_files=("${!file_presence[@]}")
# Sort the unique files
IFS=$'\n' sorted_unique_files=($(sort <<<"${unique_files[*]}"))
unset IFS
# Print the header row
echo -n "File"
for file in "$@"; do
echo -n ",$file"
done
echo
# Print the file presence for each unique file
for file in "${sorted_unique_files[@]}"; do
# Check if the file is present in all compared files
present_in_all=true
for txt_file in "$@"; do
if [[ ! "${file_presence[$file]}" =~ "$txt_file" ]]; then
present_in_all=false
break
fi
done
# Exclude files present in all compared files
if [ "$present_in_all" = true ]; then
continue
fi
# Print the file and its presence in each compared file
echo -n "$file"
for txt_file in "$@"; do
if [[ "${file_presence[$file]}" =~ "$txt_file" ]]; then
echo -n ",Y"
else
echo -n ","
fi
done
echo
done