Last active
August 21, 2023 18:14
-
-
Save zoolu-got-rhythm/53d881bfb5b2cf4997e5d3bbddf9f84a to your computer and use it in GitHub Desktop.
find all files with console.log's in a directory and count total, useful for JavaScript and Typescript projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# this script has been tested on mac bash/terminal | |
# test valid input argument (directory path) | |
if [ $# -eq 0 ]; then | |
echo "no directory to search from supplied" | |
exit 1 | |
else | |
ls $1 &> /dev/null | |
if [ "$?" -ne "0" ]; then | |
echo "not a valid directory path" | |
exit 1 | |
fi | |
fi | |
# if valid input directory path | |
dir=$1 | |
echo "searching for console.log's from root dir: $dir" | |
n=0 | |
for f in $(find $dir -type f -print); do | |
# console\s*(\.|\.\n|\n\.)\s*log is new console.log pattern to match for | |
# console.log was original pattern match/very primitive | |
console_logs_found_in_file=$(cat $f | grep -i -o -E 'console\s*(\.|\.\n|\n\.)\s*log' | wc -l | tr -d '[:blank:]') | |
if [ $console_logs_found_in_file -gt 0 ]; then | |
echo "$console_logs_found_in_file found in $f" | |
n=$((n + console_logs_found_in_file)) | |
fi | |
done | |
echo "total of $n console.log's found" | |
exit 0 # not sure if this needed really, default exit of program/script may be exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment