Skip to content

Instantly share code, notes, and snippets.

@textarcana
Last active March 18, 2021 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save textarcana/3e72a4d6adb05cf57029654347881b73 to your computer and use it in GitHub Desktop.
Save textarcana/3e72a4d6adb05cf57029654347881b73 to your computer and use it in GitHub Desktop.
Profanity search command line tool.
#!/usr/bin/env bash
set -Eeuo pipefail
profane_regex=$(
perl -e '
use Bad::Words;
my $wordref = new Bad::Words;
my $updated = $wordref->remove(qw(
xxx
));
my $regex = join("|", @$updated);
print qq{\\b($regex)\\b}')
# Mac only allows ~5k open files by default
ulimit -Sn 10000
# Search all files except for binaries. That is what the file/awk
# lines are doing here: filtering out binary files.
# cf https://unix.stackexchange.com/questions/46276/finding-all-non-binary-files
find . \
-not -name "*.min.*" \
-not -name "*bootstrap*" \
-not -name "*jquery*" \
-not -name "*lodash*" \
-type f \
-exec file {} + \
| awk -F: '/ASCII text/ {print $1}' \
| parallel -k -j6 -n 4 -m "ack --group --color --nofilter \"${profane_regex}\"" {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment