diff options
author | Adam Hovorka <[email protected]> | 2018-09-30 20:36:27 -0600 |
---|---|---|
committer | Adam Hovorka <[email protected]> | 2018-09-30 20:36:27 -0600 |
commit | 9c1224578330135406ddc9f461184ff1f6756c0c (patch) | |
tree | 0afbaceff14b98919c04048bdf5d11a5a850289c /base/pr-dups | |
parent | fc7fc47c946f49040df60dc3e3c4499399975125 (diff) |
Add some more random utilities/functions
Diffstat (limited to 'base/pr-dups')
-rwxr-xr-x | base/pr-dups | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/base/pr-dups b/base/pr-dups new file mode 100755 index 0000000..211ab64 --- /dev/null +++ b/base/pr-dups @@ -0,0 +1,55 @@ +#!/usr/bin/env perl + +# Finds duplicate adjacent words. +# http://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/ + +use strict ; + +my $DupCount = 0 ; + +if (!@ARGV) { + print "Usage: dups <file> ...\n" ; + exit ; +} + +while (1) { + my $FileName = shift @ARGV ; + + # Exit code = number of duplicates found. + exit $DupCount if (!$FileName) ; + + open FILE, $FileName or die $!; + + my $LastWord = "" ; + my $LineNum = 0 ; + + while (<FILE>) { + chomp ; + + $LineNum ++ ; + + my @words = split (/(\W+)/) ; + + foreach my $word (@words) { + # Skip spaces: + next if $word =~ /^\s*$/ ; + + # Skip punctuation: + if ($word =~ /^\W+$/) { + $LastWord = "" ; + next ; + } + + # Found a dup? + if (lc($word) eq lc($LastWord)) { + print "$FileName:$LineNum $word\n" ; + $DupCount ++ ; + } # Thanks to Sean Cronin for tip on case. + + # Mark this as the last word: + $LastWord = $word ; + } + } + + close FILE ; +} |