|
2 | 2 |
|
3 | 3 | function printResult(for_lines) {
|
4 | 4 | for (idx = 0; idx < length(for_lines); idx++) {
|
5 |
| - line=for_lines[idx] |
6 |
| - count=line_count_array[storeLine(line)] |
7 |
| - |
8 |
| - #printf "DEBUG 1: %7s %s, index: %s\n", count, line, idx |
| 5 | + line = for_lines[idx] |
| 6 | + count = line_count_array[caseAwareLine(line)] |
| 7 | + #printf "DEBUG: %s %s, index: %s, uq_opt_only_repeated: %s\n", count, line, idx, uq_opt_only_repeated |
9 | 8 |
|
10 | 9 | if (uq_opt_only_unique) {
|
11 | 10 | if (count == 1) printLine(count, line)
|
12 | 11 | } else {
|
13 |
| - #printf "DEBUG 2: %7s %s uq_opt_only_repeated: %s\n", count, line, uq_opt_only_repeated |
14 |
| - |
15 |
| - if (uq_opt_only_repeated && count <= 1) { |
16 |
| - continue |
17 |
| - } |
| 12 | + if (uq_opt_only_repeated && count <= 1) continue |
18 | 13 |
|
19 |
| - if (uq_opt_repeated_method == "prepend" || uq_opt_repeated_method == "separate" && outputted) { |
20 |
| - if (!compareLine(line, outputted)) print "" |
| 14 | + if (uq_opt_repeated_method == "prepend" || uq_opt_repeated_method == "separate" && previous_output) { |
| 15 | + if (line != previous_output) print "" |
21 | 16 | }
|
22 | 17 |
|
23 | 18 | printLine(count, line)
|
24 |
| - outputted=line |
| 19 | + previous_output = line |
25 | 20 | }
|
26 | 21 | }
|
27 | 22 | }
|
28 | 23 |
|
29 | 24 | function printLine(count, line) {
|
30 |
| - if (uq_opt_count) { |
31 |
| - printf "%7s %s%s", count, line, ORS |
32 |
| - } else { |
33 |
| - print line |
34 |
| - } |
35 |
| -} |
36 |
| - |
37 |
| -function storeLine(line) { |
38 |
| - if (uq_opt_ignore_case) { |
39 |
| - return tolower(line) |
40 |
| - } else { |
41 |
| - return line |
42 |
| - } |
| 25 | + if (uq_opt_count) printf "%7s %s%s", count, line, ORS |
| 26 | + else print line |
43 | 27 | }
|
44 | 28 |
|
45 |
| -function compareLine(line1, line2) { |
46 |
| - return storeLine(line1) == storeLine(line2) |
| 29 | +function caseAwareLine(line) { |
| 30 | + if (IGNORECASE) return tolower(line) |
| 31 | + else return line |
47 | 32 | }
|
48 | 33 |
|
49 |
| - |
50 | 34 | BEGIN {
|
51 | 35 | if (uq_opt_zero_terminated) {
|
52 | 36 | RS = "\0"
|
53 | 37 | ORS = "\0"
|
54 | 38 | }
|
55 | 39 | }
|
56 | 40 |
|
57 |
| - |
58 | 41 | {
|
59 | 42 | # use index to keep lines order
|
60 |
| - lines[line_index++] = $0 |
| 43 | + original_lines[line_index++] = $0 |
61 | 44 |
|
62 |
| - store_line=storeLine($0) |
| 45 | + case_aware_line = caseAwareLine($0) |
63 | 46 | # line_count_array: line content -> count
|
64 |
| - if (++line_count_array[store_line] == 1) { |
| 47 | + if (++line_count_array[case_aware_line] == 1) { |
65 | 48 | # use index to keep lines order
|
66 |
| - deduplicated_lines[deduplicated_line_index++] = store_line |
| 49 | + deduplicated_lines[deduplicated_line_index++] = case_aware_line |
67 | 50 | }
|
68 | 51 | }
|
69 | 52 |
|
70 |
| - |
71 | 53 | END {
|
72 |
| - if (uq_opt_all_repeated) printResult(lines) |
| 54 | + if (uq_opt_all_repeated) printResult(original_lines) |
73 | 55 | else printResult(deduplicated_lines)
|
74 | 56 | }
|
0 commit comments