bash: awk write each match to a file and increment filename

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I can't figure out, how to seperate per match and make print create a new file each cert.



awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ print > outputlist ' inputlist


I tried it already with a while read loop, but that didn't work.










share|improve this question






























    1















    I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I can't figure out, how to seperate per match and make print create a new file each cert.



    awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ print > outputlist ' inputlist


    I tried it already with a while read loop, but that didn't work.










    share|improve this question


























      1












      1








      1








      I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I can't figure out, how to seperate per match and make print create a new file each cert.



      awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ print > outputlist ' inputlist


      I tried it already with a while read loop, but that didn't work.










      share|improve this question
















      I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I can't figure out, how to seperate per match and make print create a new file each cert.



      awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ print > outputlist ' inputlist


      I tried it already with a while read loop, but that didn't work.







      awk certificates






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 12 at 19:26









      Rui F Ribeiro

      42k1483142




      42k1483142










      asked Mar 11 at 16:01









      Mickey MazurekMickey Mazurek

      83




      83




















          1 Answer
          1






          active

          oldest

          votes


















          0














          Give a try to this:



          awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist


          I always have this page open aside when writing awk script: Awk



          Files generated:



          $ ls certificate*
          certificate1.txt certificate2.txt





          share|improve this answer

























          • This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)

            – Mickey Mazurek
            Mar 11 at 16:20











          • It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^

            – Mickey Mazurek
            Mar 12 at 8:17












          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          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%2f505665%2fbash-awk-write-each-match-to-a-file-and-increment-filename%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Give a try to this:



          awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist


          I always have this page open aside when writing awk script: Awk



          Files generated:



          $ ls certificate*
          certificate1.txt certificate2.txt





          share|improve this answer

























          • This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)

            – Mickey Mazurek
            Mar 11 at 16:20











          • It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^

            – Mickey Mazurek
            Mar 12 at 8:17
















          0














          Give a try to this:



          awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist


          I always have this page open aside when writing awk script: Awk



          Files generated:



          $ ls certificate*
          certificate1.txt certificate2.txt





          share|improve this answer

























          • This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)

            – Mickey Mazurek
            Mar 11 at 16:20











          • It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^

            – Mickey Mazurek
            Mar 12 at 8:17














          0












          0








          0







          Give a try to this:



          awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist


          I always have this page open aside when writing awk script: Awk



          Files generated:



          $ ls certificate*
          certificate1.txt certificate2.txt





          share|improve this answer















          Give a try to this:



          awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist


          I always have this page open aside when writing awk script: Awk



          Files generated:



          $ ls certificate*
          certificate1.txt certificate2.txt






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 12 at 7:46

























          answered Mar 11 at 16:14









          Jay jargotJay jargot

          97138




          97138












          • This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)

            – Mickey Mazurek
            Mar 11 at 16:20











          • It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^

            – Mickey Mazurek
            Mar 12 at 8:17


















          • This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)

            – Mickey Mazurek
            Mar 11 at 16:20











          • It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^

            – Mickey Mazurek
            Mar 12 at 8:17

















          This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)

          – Mickey Mazurek
          Mar 11 at 16:20





          This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)

          – Mickey Mazurek
          Mar 11 at 16:20













          It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^

          – Mickey Mazurek
          Mar 12 at 8:17






          It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^

          – Mickey Mazurek
          Mar 12 at 8:17


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505665%2fbash-awk-write-each-match-to-a-file-and-increment-filename%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay