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

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question

























    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?







    share|improve this question























      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?







      share|improve this question













      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?









      share|improve this question












      share|improve this question




      share|improve this question








      edited May 18 at 20:43
























      asked May 18 at 20:27









      Sam

      132




      132




















          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





          share|improve this answer























          • 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










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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






























          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





          share|improve this answer























          • 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














          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





          share|improve this answer























          • 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












          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





          share|improve this answer















          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






          share|improve this answer















          share|improve this answer



          share|improve this answer








          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
















          • 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












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)