-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathuniq.sh
More file actions
68 lines (34 loc) · 1.37 KB
/
Copy pathuniq.sh
File metadata and controls
68 lines (34 loc) · 1.37 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
60
61
62
63
64
65
66
67
## Retain single copy of duplicates
printf 'red\nred\nred\ngreen\nred\nblue\nblue' | uniq
printf 'red\nred\nred\ngreen\nred\nblue\nblue' | sort | uniq
printf '2 balls\n13 pens\n2 pins\n13 pens\n' | sort -n | uniq
printf 'red\nred\nred\ngreen\nred\nblue\nblue' | awk '!seen[$0]++'
## Duplicates only
cat purchases.txt
sort purchases.txt | uniq -d
sort purchases.txt | uniq -D
## Unique only
sort purchases.txt | uniq -u
printf 'red\nred\nred\ngreen\nred\nblue\nblue' | uniq -u
## Grouping similar lines
sort purchases.txt | uniq --group
sort purchases.txt | uniq --all-repeated=prepend
## Prefix count
sort purchases.txt | uniq -c
sort purchases.txt | uniq -dc
sort purchases.txt | uniq -c | sort -n
sort purchases.txt | uniq -c | sort -nr
## Ignoring case
printf 'hat\nbat\nHAT\ncar\nbat\nmat\nmoat' | sort -f | uniq -iD
## Partial match
printf '2 cars\n5 cars\n10 jeeps\n5 jeeps\n3 trucks\n' | uniq -f1 --group
printf '2 cars\n5 cars\n1 jeeps\n5 jeeps\n3 trucks\n' | uniq -f1
printf '* red\n- green\n* green\n* blue\n= blue' | uniq -s1
printf '1) apple\n1) almond\n2) banana\n3) cherry' | uniq -w2
printf '2 @blue\n10 :black\n5 :cherry\n3 @chalk' | uniq -f1 -s2 -w2
## Specifying output file
printf 'apple\napple\nbanana\ncherry\ncherry\ncherry' > ip.txt
uniq ip.txt op.txt
cat op.txt
## NUL separator
printf 'cherry\0cherry\0cherry\0apple\0banana' | uniq -z | cat -v