Finding the Count for a String on Multiple Zipped Files in Multiple Directories (non aggregated)

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'm trying to figure out the number of lines that contain the strings "event" and "type". The files I want to search through are in multiple folders and are zipped. I'm able to get an aggregated count of what I'm looking for, but my goal is to have the count displayed for each file. This is what I'm currently using:
zcat
/folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1* |
grep 'event' | grep 'type' | wc -l
And my output is:
86446
But I want my output to look like:
result-2018-05-10.log.gz: 1000
result-2018-05-11.log.gz: 3000
result-2018-05-12.log.gz: 20000
result-2018-05-13.log.gz: 4446
result-2018-05-14.log.gz: 12000
result-2018-05-15.log.gz: 10000
result-2018-05-16.log.gz: 15000
result-2018-05-17.log.gz: 5000
result-2018-05-18.log.gz: 6000
result-2018-05-19.log.gz: 10000
Any suggestions?
grep string zip gzip wc
add a comment |Â
up vote
2
down vote
favorite
I'm trying to figure out the number of lines that contain the strings "event" and "type". The files I want to search through are in multiple folders and are zipped. I'm able to get an aggregated count of what I'm looking for, but my goal is to have the count displayed for each file. This is what I'm currently using:
zcat
/folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1* |
grep 'event' | grep 'type' | wc -l
And my output is:
86446
But I want my output to look like:
result-2018-05-10.log.gz: 1000
result-2018-05-11.log.gz: 3000
result-2018-05-12.log.gz: 20000
result-2018-05-13.log.gz: 4446
result-2018-05-14.log.gz: 12000
result-2018-05-15.log.gz: 10000
result-2018-05-16.log.gz: 15000
result-2018-05-17.log.gz: 5000
result-2018-05-18.log.gz: 6000
result-2018-05-19.log.gz: 10000
Any suggestions?
grep string zip gzip wc
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm trying to figure out the number of lines that contain the strings "event" and "type". The files I want to search through are in multiple folders and are zipped. I'm able to get an aggregated count of what I'm looking for, but my goal is to have the count displayed for each file. This is what I'm currently using:
zcat
/folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1* |
grep 'event' | grep 'type' | wc -l
And my output is:
86446
But I want my output to look like:
result-2018-05-10.log.gz: 1000
result-2018-05-11.log.gz: 3000
result-2018-05-12.log.gz: 20000
result-2018-05-13.log.gz: 4446
result-2018-05-14.log.gz: 12000
result-2018-05-15.log.gz: 10000
result-2018-05-16.log.gz: 15000
result-2018-05-17.log.gz: 5000
result-2018-05-18.log.gz: 6000
result-2018-05-19.log.gz: 10000
Any suggestions?
grep string zip gzip wc
I'm trying to figure out the number of lines that contain the strings "event" and "type". The files I want to search through are in multiple folders and are zipped. I'm able to get an aggregated count of what I'm looking for, but my goal is to have the count displayed for each file. This is what I'm currently using:
zcat
/folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1* |
grep 'event' | grep 'type' | wc -l
And my output is:
86446
But I want my output to look like:
result-2018-05-10.log.gz: 1000
result-2018-05-11.log.gz: 3000
result-2018-05-12.log.gz: 20000
result-2018-05-13.log.gz: 4446
result-2018-05-14.log.gz: 12000
result-2018-05-15.log.gz: 10000
result-2018-05-16.log.gz: 15000
result-2018-05-17.log.gz: 5000
result-2018-05-18.log.gz: 6000
result-2018-05-19.log.gz: 10000
Any suggestions?
grep string zip gzip wc
edited May 18 at 20:43
asked May 18 at 20:27
Sam
132
132
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
For only two tests, this should be enough:
zgrep -E -c 'event.*type|type.*event' /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*
Testing if a line contains type and event is the same as testing if it contains type followed later by event or event followed later by type. This wouldn't scale well if a 3rd test was needed.
Then adding something like | sed 's#^.*/##' should give the exact result in the question.
UPDATE:
For something more generic, a loop seems better, so:
for i in /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*; do
printf '%s: ' "$(basename "$i")"
zcat < "$i" | grep 'filter1' | grep 'filter 2' | grep 'filter3' | wc -l
done
I'm actually grepping a lot of strings, I limited it to two to simplify the question. But this is still good to know! Thanks!
â Sam
May 18 at 21:04
so I added a more generic case. would that be fine?
â A.B
May 18 at 21:15
Wow, works perfectly. Thanks so much!
â Sam
May 18 at 21:19
if you think this was the solution you should mark it as the solution
â A.B
May 19 at 0:38
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
For only two tests, this should be enough:
zgrep -E -c 'event.*type|type.*event' /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*
Testing if a line contains type and event is the same as testing if it contains type followed later by event or event followed later by type. This wouldn't scale well if a 3rd test was needed.
Then adding something like | sed 's#^.*/##' should give the exact result in the question.
UPDATE:
For something more generic, a loop seems better, so:
for i in /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*; do
printf '%s: ' "$(basename "$i")"
zcat < "$i" | grep 'filter1' | grep 'filter 2' | grep 'filter3' | wc -l
done
I'm actually grepping a lot of strings, I limited it to two to simplify the question. But this is still good to know! Thanks!
â Sam
May 18 at 21:04
so I added a more generic case. would that be fine?
â A.B
May 18 at 21:15
Wow, works perfectly. Thanks so much!
â Sam
May 18 at 21:19
if you think this was the solution you should mark it as the solution
â A.B
May 19 at 0:38
add a comment |Â
up vote
1
down vote
accepted
For only two tests, this should be enough:
zgrep -E -c 'event.*type|type.*event' /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*
Testing if a line contains type and event is the same as testing if it contains type followed later by event or event followed later by type. This wouldn't scale well if a 3rd test was needed.
Then adding something like | sed 's#^.*/##' should give the exact result in the question.
UPDATE:
For something more generic, a loop seems better, so:
for i in /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*; do
printf '%s: ' "$(basename "$i")"
zcat < "$i" | grep 'filter1' | grep 'filter 2' | grep 'filter3' | wc -l
done
I'm actually grepping a lot of strings, I limited it to two to simplify the question. But this is still good to know! Thanks!
â Sam
May 18 at 21:04
so I added a more generic case. would that be fine?
â A.B
May 18 at 21:15
Wow, works perfectly. Thanks so much!
â Sam
May 18 at 21:19
if you think this was the solution you should mark it as the solution
â A.B
May 19 at 0:38
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
For only two tests, this should be enough:
zgrep -E -c 'event.*type|type.*event' /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*
Testing if a line contains type and event is the same as testing if it contains type followed later by event or event followed later by type. This wouldn't scale well if a 3rd test was needed.
Then adding something like | sed 's#^.*/##' should give the exact result in the question.
UPDATE:
For something more generic, a loop seems better, so:
for i in /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*; do
printf '%s: ' "$(basename "$i")"
zcat < "$i" | grep 'filter1' | grep 'filter 2' | grep 'filter3' | wc -l
done
For only two tests, this should be enough:
zgrep -E -c 'event.*type|type.*event' /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*
Testing if a line contains type and event is the same as testing if it contains type followed later by event or event followed later by type. This wouldn't scale well if a 3rd test was needed.
Then adding something like | sed 's#^.*/##' should give the exact result in the question.
UPDATE:
For something more generic, a loop seems better, so:
for i in /folder1/folderA,folderB,folderC/folder2/folder3/result-2018-05-1*; do
printf '%s: ' "$(basename "$i")"
zcat < "$i" | grep 'filter1' | grep 'filter 2' | grep 'filter3' | wc -l
done
edited May 18 at 21:17
answered May 18 at 21:01
A.B
2,4901315
2,4901315
I'm actually grepping a lot of strings, I limited it to two to simplify the question. But this is still good to know! Thanks!
â Sam
May 18 at 21:04
so I added a more generic case. would that be fine?
â A.B
May 18 at 21:15
Wow, works perfectly. Thanks so much!
â Sam
May 18 at 21:19
if you think this was the solution you should mark it as the solution
â A.B
May 19 at 0:38
add a comment |Â
I'm actually grepping a lot of strings, I limited it to two to simplify the question. But this is still good to know! Thanks!
â Sam
May 18 at 21:04
so I added a more generic case. would that be fine?
â A.B
May 18 at 21:15
Wow, works perfectly. Thanks so much!
â Sam
May 18 at 21:19
if you think this was the solution you should mark it as the solution
â A.B
May 19 at 0:38
I'm actually grepping a lot of strings, I limited it to two to simplify the question. But this is still good to know! Thanks!
â Sam
May 18 at 21:04
I'm actually grepping a lot of strings, I limited it to two to simplify the question. But this is still good to know! Thanks!
â Sam
May 18 at 21:04
so I added a more generic case. would that be fine?
â A.B
May 18 at 21:15
so I added a more generic case. would that be fine?
â A.B
May 18 at 21:15
Wow, works perfectly. Thanks so much!
â Sam
May 18 at 21:19
Wow, works perfectly. Thanks so much!
â Sam
May 18 at 21:19
if you think this was the solution you should mark it as the solution
â A.B
May 19 at 0:38
if you think this was the solution you should mark it as the solution
â A.B
May 19 at 0:38
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%2f444703%2ffinding-the-count-for-a-string-on-multiple-zipped-files-in-multiple-directories%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