Skip to content

Instantly share code, notes, and snippets.

@sandcastle
Last active June 13, 2016 07:33
Show Gist options
  • Select an option

  • Save sandcastle/d24064081d37d4becaadf4edd5235c13 to your computer and use it in GitHub Desktop.

Select an option

Save sandcastle/d24064081d37d4becaadf4edd5235c13 to your computer and use it in GitHub Desktop.
Finds the number of times a word occurs per file in a directory and its subdirectories
#!/bin/sh
# LOGIC:
#
# 1. Find all *.ts files the current directory and all subdirectories
#
# for f in $(find . -name '*.ts');
#
# 2. Loop through all files and do an action
#
# for f in $(find . -name '*.ts'); do echo $f; done
#
# 3. Count the occurences of the word "export"
#
# - Print the file
# - Find occurances of "export"
# - Count the occurances of the word
# - Trim the string
#
# cat $f | grep export | wc -l | sed 's/ //g'
#
for f in $(find . -name '*.ts'); do echo "$f $(cat $f | grep export | wc -l | sed 's/ //g')"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment