Search for multiple pattern in same line












2














I'm trying to search for different patterns in the same line and then print them in this way.



This is the text:



`voices` VALUES (409663,1957,2594,'mech Brands LC - BO GB6: pic - LST  September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');

`others` VALUES (409664,1957,2595,'mech Brands LC - BO NZ6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');

`voices` VALUES (409684,628,2622,'Pic Productions Com - pic: perV things September 2017',NULL,1,0,'2017-09-24 07:35:22',NULL,NULL,628,0,0,NULL,'2017-09-24 07:35:22');


And I would like to output like this:



`voices` - mech Brands LC

`others` - mech Brands LC

`voices` - Pic Productions Com


This is what I have tried but it gives me the output in different lines



cat file.txt | grep -Pzo "mech Brands LC|Pic Productions Com|`.*`"

`invoices`

mech Brands LC

`invoices`

mech Brands LC

`invoices`

Pic Productions Com


Could somebody help me?



Thanks!










share|improve this question





























    2














    I'm trying to search for different patterns in the same line and then print them in this way.



    This is the text:



    `voices` VALUES (409663,1957,2594,'mech Brands LC - BO GB6: pic - LST  September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');

    `others` VALUES (409664,1957,2595,'mech Brands LC - BO NZ6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');

    `voices` VALUES (409684,628,2622,'Pic Productions Com - pic: perV things September 2017',NULL,1,0,'2017-09-24 07:35:22',NULL,NULL,628,0,0,NULL,'2017-09-24 07:35:22');


    And I would like to output like this:



    `voices` - mech Brands LC

    `others` - mech Brands LC

    `voices` - Pic Productions Com


    This is what I have tried but it gives me the output in different lines



    cat file.txt | grep -Pzo "mech Brands LC|Pic Productions Com|`.*`"

    `invoices`

    mech Brands LC

    `invoices`

    mech Brands LC

    `invoices`

    Pic Productions Com


    Could somebody help me?



    Thanks!










    share|improve this question



























      2












      2








      2







      I'm trying to search for different patterns in the same line and then print them in this way.



      This is the text:



      `voices` VALUES (409663,1957,2594,'mech Brands LC - BO GB6: pic - LST  September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');

      `others` VALUES (409664,1957,2595,'mech Brands LC - BO NZ6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');

      `voices` VALUES (409684,628,2622,'Pic Productions Com - pic: perV things September 2017',NULL,1,0,'2017-09-24 07:35:22',NULL,NULL,628,0,0,NULL,'2017-09-24 07:35:22');


      And I would like to output like this:



      `voices` - mech Brands LC

      `others` - mech Brands LC

      `voices` - Pic Productions Com


      This is what I have tried but it gives me the output in different lines



      cat file.txt | grep -Pzo "mech Brands LC|Pic Productions Com|`.*`"

      `invoices`

      mech Brands LC

      `invoices`

      mech Brands LC

      `invoices`

      Pic Productions Com


      Could somebody help me?



      Thanks!










      share|improve this question















      I'm trying to search for different patterns in the same line and then print them in this way.



      This is the text:



      `voices` VALUES (409663,1957,2594,'mech Brands LC - BO GB6: pic - LST  September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');

      `others` VALUES (409664,1957,2595,'mech Brands LC - BO NZ6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');

      `voices` VALUES (409684,628,2622,'Pic Productions Com - pic: perV things September 2017',NULL,1,0,'2017-09-24 07:35:22',NULL,NULL,628,0,0,NULL,'2017-09-24 07:35:22');


      And I would like to output like this:



      `voices` - mech Brands LC

      `others` - mech Brands LC

      `voices` - Pic Productions Com


      This is what I have tried but it gives me the output in different lines



      cat file.txt | grep -Pzo "mech Brands LC|Pic Productions Com|`.*`"

      `invoices`

      mech Brands LC

      `invoices`

      mech Brands LC

      `invoices`

      Pic Productions Com


      Could somebody help me?



      Thanks!







      mysql search






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 9:16









      juergen d

      159k24200260




      159k24200260










      asked Nov 20 '18 at 9:16









      mmac-rio89

      3329




      3329
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I suggest using sed for this:



          sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          Or, with POSIX ERE syntax



          sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          See the online sed demo



          Details





          • ^ - start of string


          • (`[^`]*`) - Group 1: a backtick, 0+ chars other than backticks and a backtick


          • .* - any 0+ chars


          • (mech Brands LC|Pic Productions Com) - Group 2: either mech Brands LC or Pic Productions Com substrings


          • .* - any 0+ chars


          • 1 - 2 - the match is replaced with Group 1, - and Group 2 values.






          share|improve this answer

















          • 1




            Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
            – mmac-rio89
            Nov 20 '18 at 10:07











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f53389697%2fsearch-for-multiple-pattern-in-same-line%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









          1














          I suggest using sed for this:



          sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          Or, with POSIX ERE syntax



          sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          See the online sed demo



          Details





          • ^ - start of string


          • (`[^`]*`) - Group 1: a backtick, 0+ chars other than backticks and a backtick


          • .* - any 0+ chars


          • (mech Brands LC|Pic Productions Com) - Group 2: either mech Brands LC or Pic Productions Com substrings


          • .* - any 0+ chars


          • 1 - 2 - the match is replaced with Group 1, - and Group 2 values.






          share|improve this answer

















          • 1




            Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
            – mmac-rio89
            Nov 20 '18 at 10:07
















          1














          I suggest using sed for this:



          sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          Or, with POSIX ERE syntax



          sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          See the online sed demo



          Details





          • ^ - start of string


          • (`[^`]*`) - Group 1: a backtick, 0+ chars other than backticks and a backtick


          • .* - any 0+ chars


          • (mech Brands LC|Pic Productions Com) - Group 2: either mech Brands LC or Pic Productions Com substrings


          • .* - any 0+ chars


          • 1 - 2 - the match is replaced with Group 1, - and Group 2 values.






          share|improve this answer

















          • 1




            Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
            – mmac-rio89
            Nov 20 '18 at 10:07














          1












          1








          1






          I suggest using sed for this:



          sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          Or, with POSIX ERE syntax



          sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          See the online sed demo



          Details





          • ^ - start of string


          • (`[^`]*`) - Group 1: a backtick, 0+ chars other than backticks and a backtick


          • .* - any 0+ chars


          • (mech Brands LC|Pic Productions Com) - Group 2: either mech Brands LC or Pic Productions Com substrings


          • .* - any 0+ chars


          • 1 - 2 - the match is replaced with Group 1, - and Group 2 values.






          share|improve this answer












          I suggest using sed for this:



          sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          Or, with POSIX ERE syntax



          sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt


          See the online sed demo



          Details





          • ^ - start of string


          • (`[^`]*`) - Group 1: a backtick, 0+ chars other than backticks and a backtick


          • .* - any 0+ chars


          • (mech Brands LC|Pic Productions Com) - Group 2: either mech Brands LC or Pic Productions Com substrings


          • .* - any 0+ chars


          • 1 - 2 - the match is replaced with Group 1, - and Group 2 values.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 9:27









          Wiktor Stribiżew

          308k16126202




          308k16126202








          • 1




            Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
            – mmac-rio89
            Nov 20 '18 at 10:07














          • 1




            Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
            – mmac-rio89
            Nov 20 '18 at 10:07








          1




          1




          Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
          – mmac-rio89
          Nov 20 '18 at 10:07




          Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
          – mmac-rio89
          Nov 20 '18 at 10:07


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2fstackoverflow.com%2fquestions%2f53389697%2fsearch-for-multiple-pattern-in-same-line%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

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy