Last active
June 13, 2016 07:33
-
-
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
This file contains hidden or 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 | |
| # 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