Extract multiple occurrences in the same line of a string between two delimiters

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











up vote
1
down vote

favorite












This one is tricky... input has multiple occurrences per line over several lines. many "id=" lines exist, but I only want ones starting with ai-c " id="



Example input (two long lines):



d-fl ai-c" id="3af3a73f26a63a-list-" lima zulu bravo hotel d-fl ai-c" id="7ab8273f273e7273f82c2-list-" alpha id="8372364fa2361ab1-list-" hotel foxtrox mike d-fl ai-c" id="973a72b72c72df12a2-list-" uniform hotel


start of second line golf november d-fl ai-c" id="83hd826ab712cc71-list-" bravo mike mike d-fl ai-c" id="7612364bab72a-list-" golf mike



Output desired is:



id="3af3a73f26a63a"

id="7ab8273f273e7273f82c2"

id="973a72b72c72df12a2"

id="83hd826ab712cc71"

id="7612364bab72a"


All of the script examples I've seen only seem to work for the first occurrence in a line.










share|improve this question



























    up vote
    1
    down vote

    favorite












    This one is tricky... input has multiple occurrences per line over several lines. many "id=" lines exist, but I only want ones starting with ai-c " id="



    Example input (two long lines):



    d-fl ai-c" id="3af3a73f26a63a-list-" lima zulu bravo hotel d-fl ai-c" id="7ab8273f273e7273f82c2-list-" alpha id="8372364fa2361ab1-list-" hotel foxtrox mike d-fl ai-c" id="973a72b72c72df12a2-list-" uniform hotel


    start of second line golf november d-fl ai-c" id="83hd826ab712cc71-list-" bravo mike mike d-fl ai-c" id="7612364bab72a-list-" golf mike



    Output desired is:



    id="3af3a73f26a63a"

    id="7ab8273f273e7273f82c2"

    id="973a72b72c72df12a2"

    id="83hd826ab712cc71"

    id="7612364bab72a"


    All of the script examples I've seen only seem to work for the first occurrence in a line.










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      This one is tricky... input has multiple occurrences per line over several lines. many "id=" lines exist, but I only want ones starting with ai-c " id="



      Example input (two long lines):



      d-fl ai-c" id="3af3a73f26a63a-list-" lima zulu bravo hotel d-fl ai-c" id="7ab8273f273e7273f82c2-list-" alpha id="8372364fa2361ab1-list-" hotel foxtrox mike d-fl ai-c" id="973a72b72c72df12a2-list-" uniform hotel


      start of second line golf november d-fl ai-c" id="83hd826ab712cc71-list-" bravo mike mike d-fl ai-c" id="7612364bab72a-list-" golf mike



      Output desired is:



      id="3af3a73f26a63a"

      id="7ab8273f273e7273f82c2"

      id="973a72b72c72df12a2"

      id="83hd826ab712cc71"

      id="7612364bab72a"


      All of the script examples I've seen only seem to work for the first occurrence in a line.










      share|improve this question















      This one is tricky... input has multiple occurrences per line over several lines. many "id=" lines exist, but I only want ones starting with ai-c " id="



      Example input (two long lines):



      d-fl ai-c" id="3af3a73f26a63a-list-" lima zulu bravo hotel d-fl ai-c" id="7ab8273f273e7273f82c2-list-" alpha id="8372364fa2361ab1-list-" hotel foxtrox mike d-fl ai-c" id="973a72b72c72df12a2-list-" uniform hotel


      start of second line golf november d-fl ai-c" id="83hd826ab712cc71-list-" bravo mike mike d-fl ai-c" id="7612364bab72a-list-" golf mike



      Output desired is:



      id="3af3a73f26a63a"

      id="7ab8273f273e7273f82c2"

      id="973a72b72c72df12a2"

      id="83hd826ab712cc71"

      id="7612364bab72a"


      All of the script examples I've seen only seem to work for the first occurrence in a line.







      text-processing awk sed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 7 at 5:40









      jasonwryan

      47.1k14127178




      47.1k14127178










      asked Aug 7 at 3:30









      CanRegExtoSaveMyLife

      61




      61




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          One way to do this is:



          grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'


          Where we use GNU grep with the Perl feature turned on and the -o option to output just the matche(s), rather than the default whole line when a match is found.



          Output:



          id="3af3a73f26a63a"
          id="7ab8273f273e7273f82c2"
          id="973a72b72c72df12a2"
          id="83hd826ab712cc71"
          id="7612364bab72a"





          share|improve this answer



























            up vote
            0
            down vote













            Another way:



            sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
            id="3af3a73f26a63a"
            id="7ab8273f273e7273f82c2"
            id="973a72b72c72df12a2"
            id="83hd826ab712cc71"
            id="7612364bab72a"





            share|improve this answer




















              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%2f460941%2fextract-multiple-occurrences-in-the-same-line-of-a-string-between-two-delimiters%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote













              One way to do this is:



              grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'


              Where we use GNU grep with the Perl feature turned on and the -o option to output just the matche(s), rather than the default whole line when a match is found.



              Output:



              id="3af3a73f26a63a"
              id="7ab8273f273e7273f82c2"
              id="973a72b72c72df12a2"
              id="83hd826ab712cc71"
              id="7612364bab72a"





              share|improve this answer
























                up vote
                1
                down vote













                One way to do this is:



                grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'


                Where we use GNU grep with the Perl feature turned on and the -o option to output just the matche(s), rather than the default whole line when a match is found.



                Output:



                id="3af3a73f26a63a"
                id="7ab8273f273e7273f82c2"
                id="973a72b72c72df12a2"
                id="83hd826ab712cc71"
                id="7612364bab72a"





                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  One way to do this is:



                  grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'


                  Where we use GNU grep with the Perl feature turned on and the -o option to output just the matche(s), rather than the default whole line when a match is found.



                  Output:



                  id="3af3a73f26a63a"
                  id="7ab8273f273e7273f82c2"
                  id="973a72b72c72df12a2"
                  id="83hd826ab712cc71"
                  id="7612364bab72a"





                  share|improve this answer












                  One way to do this is:



                  grep -oP 'hai-c"hKid="[^-]*' input.file | sed -e 's/$/"/'


                  Where we use GNU grep with the Perl feature turned on and the -o option to output just the matche(s), rather than the default whole line when a match is found.



                  Output:



                  id="3af3a73f26a63a"
                  id="7ab8273f273e7273f82c2"
                  id="973a72b72c72df12a2"
                  id="83hd826ab712cc71"
                  id="7612364bab72a"






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 7 at 3:48









                  Rakesh Sharma

                  57513




                  57513






















                      up vote
                      0
                      down vote













                      Another way:



                      sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
                      id="3af3a73f26a63a"
                      id="7ab8273f273e7273f82c2"
                      id="973a72b72c72df12a2"
                      id="83hd826ab712cc71"
                      id="7612364bab72a"





                      share|improve this answer
























                        up vote
                        0
                        down vote













                        Another way:



                        sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
                        id="3af3a73f26a63a"
                        id="7ab8273f273e7273f82c2"
                        id="973a72b72c72df12a2"
                        id="83hd826ab712cc71"
                        id="7612364bab72a"





                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Another way:



                          sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
                          id="3af3a73f26a63a"
                          id="7ab8273f273e7273f82c2"
                          id="973a72b72c72df12a2"
                          id="83hd826ab712cc71"
                          id="7612364bab72a"





                          share|improve this answer












                          Another way:



                          sed ' s/d-fl ai-c" /n/g; s/-/"n/g; :L; /^id=/ P; D; bL; ' file
                          id="3af3a73f26a63a"
                          id="7ab8273f273e7273f82c2"
                          id="973a72b72c72df12a2"
                          id="83hd826ab712cc71"
                          id="7612364bab72a"






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 7 at 8:38









                          RudiC

                          1,1837




                          1,1837



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460941%2fextract-multiple-occurrences-in-the-same-line-of-a-string-between-two-delimiters%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              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