How to count occurrences of a word in all the files of a directory?
grep -roh aaa . | wc -w
Grep recursively all files and directories in the current dir searching for aaa, and output only the matches, not the entire line. Then, just use wc
to count how many words are there.
How to get occurrences of word in all files? But with count of the words per directory instead of single number
Update: The following command can be used on AIX:
#!/bin/bash
for name in /path/to/folder/* ; do
if [ ! -d "${name}" ] ; then
continue
fi
# See: https://unix.stackexchange.com/a/398414/45365
count="$(cat "${name}"/error*.log | tr '[:space:]' '[\n*]' | grep -c 'SEARCH')"
printf "%s %s\n" "${name}" "${count}"
done
On GNU/Linux, with GNU findutils
and GNU grep
:
find /path/to/folder -maxdepth 1 -type d \
-printf "%p " -exec bash -c 'grep -ro 'SEARCH' {} | wc -l' \;
Replace SEARCH
by the actual search term.
Count occurrence of list of words in multiple files
Take the output from you script and pipe it to
awk '{ arry[$1]+=$2 } END { for (i in arry) { print i" "arry[i] } }'
Count all occurrences of a string in lots of files with grep
cat * | grep -c string
How to count occurrences of a word in all the files of a directory? But with count incremented only once per word per file
So what you want is the number of files that contain that word. Easy:
grep -l word *|wc -l
Count word occurrence for all the files in a folder using Powershell
It turns out I missed the left parenthesis for the command
(Get-ChildItem -Filter "*.manifest" -Recurse | Select-String -pattern "D1" -AllMatches).matches.count
Works fine for me.
Related Topics
How to Conveniently Sync a File Between Two Git Repositories
How to Use Curl in a Shell Script
Openssh Client Hangs on Logout When Forwarding X Connections
Lowering Linux Kernel Timer Frequency
Why Would It Be Impossible to Fully Statically Link an Application
How to Open Port 2195 in Iptables Centos 6 for Activating the Apns
Can Clang Compile Code with Gcc Compiled .A Libs
Loading Module on Keyboard Hotplug
What Is Active Memory and Inactive Memory
How to Swap /Dev/Sda with /Dev/Sdb
Git Merge Branch of Another Remote
Why Using Dirname in Find Command Gives Dots for Each Match
Gpg: Sorry, No Terminal at All Requested - Can't Get Input
Linux "Free -M": Total, Used and Free Memory Values Don't Add Up
How to Determine If Lcd Monitor Is Turned on from Linux Command Line