diff options
author | Yigit Sever | 2021-11-07 23:42:15 +0300 |
---|---|---|
committer | Yigit Sever | 2021-11-07 23:42:15 +0300 |
commit | 9fa9973c2d2f91cef7bdd26cb52064c13f4d682e (patch) | |
tree | 13aa64b09bc91e16f3dd3217bf3d647559af2cf9 /.local/bin/dups | |
parent | 9382166b5522a5d9e2d62e93e702b4d0886cedb4 (diff) | |
parent | fcb2237c01bcd2b7982bb844cea4cf9447f20d03 (diff) | |
download | dotfiles-9fa9973c2d2f91cef7bdd26cb52064c13f4d682e.tar.gz dotfiles-9fa9973c2d2f91cef7bdd26cb52064c13f4d682e.tar.bz2 dotfiles-9fa9973c2d2f91cef7bdd26cb52064c13f4d682e.zip |
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '.local/bin/dups')
-rwxr-xr-x | .local/bin/dups | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/.local/bin/dups b/.local/bin/dups new file mode 100755 index 0000000..eb450f5 --- /dev/null +++ b/.local/bin/dups | |||
@@ -0,0 +1,54 @@ | |||
1 | #!/usr/bin/env perl | ||
2 | |||
3 | # Finds duplicate adjacent words. | ||
4 | |||
5 | use strict ; | ||
6 | |||
7 | my $DupCount = 0 ; | ||
8 | |||
9 | if (!@ARGV) { | ||
10 | print "usage: dups <file> ...\n" ; | ||
11 | exit ; | ||
12 | } | ||
13 | |||
14 | while (1) { | ||
15 | my $FileName = shift @ARGV ; | ||
16 | |||
17 | # Exit code = number of duplicates found. | ||
18 | exit $DupCount if (!$FileName) ; | ||
19 | |||
20 | open FILE, $FileName or die $!; | ||
21 | |||
22 | my $LastWord = "" ; | ||
23 | my $LineNum = 0 ; | ||
24 | |||
25 | while (<FILE>) { | ||
26 | chomp ; | ||
27 | |||
28 | $LineNum ++ ; | ||
29 | |||
30 | my @words = split (/(\W+)/) ; | ||
31 | |||
32 | foreach my $word (@words) { | ||
33 | # Skip spaces: | ||
34 | next if $word =~ /^\s*$/ ; | ||
35 | |||
36 | # Skip punctuation: | ||
37 | if ($word =~ /^\W+$/) { | ||
38 | $LastWord = "" ; | ||
39 | next ; | ||
40 | } | ||
41 | |||
42 | # Found a dup? | ||
43 | if (lc($word) eq lc($LastWord)) { | ||
44 | print "$FileName:$LineNum $word\n" ; | ||
45 | $DupCount ++ ; | ||
46 | } # Thanks to Sean Cronin for tip on case. | ||
47 | |||
48 | # Mark this as the last word: | ||
49 | $LastWord = $word ; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | close FILE ; | ||
54 | } | ||