-
Notifications
You must be signed in to change notification settings - Fork 25
/
dups.zsh
executable file
·55 lines (53 loc) · 1.32 KB
/
dups.zsh
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
#!/usr/bin/env zsh
##
# Duplicate detector: a general-purpose line-oriented key tracker.
#
# The input lines use this format:
#
# <key> <note>
#
# The output lines are the duplicates and use this format:
#
# <key> <note of first hit> <note of current hit>
#
# The key is any identifier you want to compare, such as a checksum.
# The key must be a command line token, i.e. no spaces, no quotes, etc.
#
# The note is anything you want in the printout, such as a file name.
# The note is only for printout; the note is not used for comparison.
#
# The output prints the note from the first matching line first,
# then the note from the second matching linee.
#
# Example file demo.txt:
#
# A Alice
# B Bob
# A Anna
#
# Example command:
#
# $ cat demo.txt | dups.zsh
# A Alice Anna
#
# To detect duplicate files, we can use a checksum:
#
# find . -type f -exec sha512sum '{}' \; | dups.zsh
#
# This script requires the zsh shell.
# If you use bash instead of zsh,
# see our repo for a bash version.
#
# Contact: Joel Parker Henderson ([email protected])
# License: Any of BSD, MIT, GPL.
# Repo: https://github.com/SixArm/sixarm_unix_shell_scripts
##
unset track
typeset -A track
while read -r key val; do
if (( ${+track[$key]} )); then
print $key $track[$key] $val
else
track[$key]="$val"
fi
done