Skip to content

Instantly share code, notes, and snippets.

@disouzam
Created October 29, 2023 22:56
Show Gist options
  • Save disouzam/d87fc8978a9a6b15576c5803daa251aa to your computer and use it in GitHub Desktop.
Save disouzam/d87fc8978a9a6b15576c5803daa251aa to your computer and use it in GitHub Desktop.
Counting files with a given word using bash
#! /bin/bash
file=./folder1/folder2/file-name-input.txt
outputfile=./folder1/folder2/file-name-output.txt
while IFS= read -r cmd; do
NUMBER_OF_FILES=$(grep --include=\*{ts,tsx} -rl './folder1' -e "$cmd" | wc -l)
printf 'Number of ocurrences: %s - Key: %s\n' "$NUMBER_OF_FILES" "$cmd" >> $outputfile
done < "$file"