Search a Keyword and get its count occurrence
up vote
0
down vote
favorite
I want to find out the occurrence of a keyword group by filename inside a directory.
Example: 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 occurrence like if a file is having 3 occurrence (like TEST1, TEST_XXX, TESTXYES) the output will be
TEST
TEST
TEST
OR If multiple files search is not possible than OUTPUT should provide all the similar string starting TEST
example
TEST
TEST_1
TEST_2
TEST4
I tried following too.
grep -c "TEST" a.txt
this gives on the count, it does not gives what was the entire text starting with TEST
text-processing grep
add a comment |
up vote
0
down vote
favorite
I want to find out the occurrence of a keyword group by filename inside a directory.
Example: 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 occurrence like if a file is having 3 occurrence (like TEST1, TEST_XXX, TESTXYES) the output will be
TEST
TEST
TEST
OR If multiple files search is not possible than OUTPUT should provide all the similar string starting TEST
example
TEST
TEST_1
TEST_2
TEST4
I tried following too.
grep -c "TEST" a.txt
this gives on the count, it does not gives what was the entire text starting with TEST
text-processing grep
For keywordTEST
does it count if it's found inRETESTS
? What about inTestament
?
– roaima
8 hours ago
1
I modified your question, tried making it readable, but you should really edit the question by yourself because it is still hard to understand what exactly you are asking for.
– jimmij
8 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to find out the occurrence of a keyword group by filename inside a directory.
Example: 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 occurrence like if a file is having 3 occurrence (like TEST1, TEST_XXX, TESTXYES) the output will be
TEST
TEST
TEST
OR If multiple files search is not possible than OUTPUT should provide all the similar string starting TEST
example
TEST
TEST_1
TEST_2
TEST4
I tried following too.
grep -c "TEST" a.txt
this gives on the count, it does not gives what was the entire text starting with TEST
text-processing grep
I want to find out the occurrence of a keyword group by filename inside a directory.
Example: 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 occurrence like if a file is having 3 occurrence (like TEST1, TEST_XXX, TESTXYES) the output will be
TEST
TEST
TEST
OR If multiple files search is not possible than OUTPUT should provide all the similar string starting TEST
example
TEST
TEST_1
TEST_2
TEST4
I tried following too.
grep -c "TEST" a.txt
this gives on the count, it does not gives what was the entire text starting with TEST
text-processing grep
text-processing grep
edited 7 hours ago
GAD3R
24.2k1748102
24.2k1748102
asked 8 hours ago
user249634
6
6
For keywordTEST
does it count if it's found inRETESTS
? What about inTestament
?
– roaima
8 hours ago
1
I modified your question, tried making it readable, but you should really edit the question by yourself because it is still hard to understand what exactly you are asking for.
– jimmij
8 hours ago
add a comment |
For keywordTEST
does it count if it's found inRETESTS
? What about inTestament
?
– roaima
8 hours ago
1
I modified your question, tried making it readable, but you should really edit the question by yourself because it is still hard to understand what exactly you are asking for.
– jimmij
8 hours ago
For keyword
TEST
does it count if it's found in RETESTS
? What about in Testament
?– roaima
8 hours ago
For keyword
TEST
does it count if it's found in RETESTS
? What about in Testament
?– roaima
8 hours ago
1
1
I modified your question, tried making it readable, but you should really edit the question by yourself because it is still hard to understand what exactly you are asking for.
– jimmij
8 hours ago
I modified your question, tried making it readable, but you should really edit the question by yourself because it is still hard to understand what exactly you are asking for.
– jimmij
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The grep -c
prints number of matching lines, so you won't get right result in combination with -o
option. I would pipe the output of grep -o
to uniq -c
:
$ echo 'test1 test2 test3' >/tmp/file1
$ echo 'test1 test2 test3 test4' >/tmp/file2
$ grep -o test /tmp/file* | uniq -c
3 /tmp/file1:test
4 /tmp/file2:test
You can pipe it further to modify the output with some text-processing tools.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The grep -c
prints number of matching lines, so you won't get right result in combination with -o
option. I would pipe the output of grep -o
to uniq -c
:
$ echo 'test1 test2 test3' >/tmp/file1
$ echo 'test1 test2 test3 test4' >/tmp/file2
$ grep -o test /tmp/file* | uniq -c
3 /tmp/file1:test
4 /tmp/file2:test
You can pipe it further to modify the output with some text-processing tools.
add a comment |
up vote
0
down vote
The grep -c
prints number of matching lines, so you won't get right result in combination with -o
option. I would pipe the output of grep -o
to uniq -c
:
$ echo 'test1 test2 test3' >/tmp/file1
$ echo 'test1 test2 test3 test4' >/tmp/file2
$ grep -o test /tmp/file* | uniq -c
3 /tmp/file1:test
4 /tmp/file2:test
You can pipe it further to modify the output with some text-processing tools.
add a comment |
up vote
0
down vote
up vote
0
down vote
The grep -c
prints number of matching lines, so you won't get right result in combination with -o
option. I would pipe the output of grep -o
to uniq -c
:
$ echo 'test1 test2 test3' >/tmp/file1
$ echo 'test1 test2 test3 test4' >/tmp/file2
$ grep -o test /tmp/file* | uniq -c
3 /tmp/file1:test
4 /tmp/file2:test
You can pipe it further to modify the output with some text-processing tools.
The grep -c
prints number of matching lines, so you won't get right result in combination with -o
option. I would pipe the output of grep -o
to uniq -c
:
$ echo 'test1 test2 test3' >/tmp/file1
$ echo 'test1 test2 test3 test4' >/tmp/file2
$ grep -o test /tmp/file* | uniq -c
3 /tmp/file1:test
4 /tmp/file2:test
You can pipe it further to modify the output with some text-processing tools.
edited 8 hours ago
answered 8 hours ago
jimmij
30.2k867102
30.2k867102
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481627%2fsearch-a-keyword-and-get-its-count-occurrence%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
For keyword
TEST
does it count if it's found inRETESTS
? What about inTestament
?– roaima
8 hours ago
1
I modified your question, tried making it readable, but you should really edit the question by yourself because it is still hard to understand what exactly you are asking for.
– jimmij
8 hours ago