I want to find out the occurrence of a keyword group by filename inside a directory.
Keyword - TEST (means TEST1, TEST2, etc. can be valid results)
Files - a.txt, b.txt etc. (inside a directory .. /tmp).
Output will be as follows.
a.txt - 4 b.txt - 5 c.txt - 0
I tried with
grep -o "TEST" a.txt and this gives only TEST and its occurrences; like if a file has 3 occurrences (like TEST1, TEST_XXX, TESTXYES) the output will be
TEST TEST TEST
OR if multiple files search is not possible then OUTPUT should provide all the similar string starting TEST; for example,
TEST TEST_1 TEST_2 TEST4
I tried the following, too.
grep -c "TEST" a.txt
but this gives only the count; it does not give what was the entire text starting with TEST.