How to extract specific values/fields from the text file?












0















Need help if somebody kindly suggest how to extract the following values/fields from the text file in Linux system.



EventCorrelationId="615-493|-1899671563||1550927718000"
CreationTime="20190225094504"
SubscriberNumber=92705073362


Text file sample data is mentioned below:



2019-02-25 09:45:04.427 FAIL RETRY: Failed for request id: 11235993 Cause: userNotReachable Info: <undef> Code: 27,USSD RequestId=11235993 OriginalId=11235993 EventCorrelationId="615-493|-1899671563||1550927718000" CreationTime="20190225094504" ResendCount=0 Timestamp=1551071704342 (Mon Feb 25 09:45:04 AFT 2019) State=STATE_SENT SubscriberNumber=92705073362 UssdText=Last event was charged 687.95 MB from 3GB Monthly, Main Account 6.00 PKR, Remaining data 2,388.75 MB (Exp 25.03.2019), Main Account 7.62 PKR1500 PKR = 32GB valid 30 Days, Dial *477*32*1#. NumberingPlan=1 Nadi=4 UssdFormat=2 









share|improve this question





























    0















    Need help if somebody kindly suggest how to extract the following values/fields from the text file in Linux system.



    EventCorrelationId="615-493|-1899671563||1550927718000"
    CreationTime="20190225094504"
    SubscriberNumber=92705073362


    Text file sample data is mentioned below:



    2019-02-25 09:45:04.427 FAIL RETRY: Failed for request id: 11235993 Cause: userNotReachable Info: <undef> Code: 27,USSD RequestId=11235993 OriginalId=11235993 EventCorrelationId="615-493|-1899671563||1550927718000" CreationTime="20190225094504" ResendCount=0 Timestamp=1551071704342 (Mon Feb 25 09:45:04 AFT 2019) State=STATE_SENT SubscriberNumber=92705073362 UssdText=Last event was charged 687.95 MB from 3GB Monthly, Main Account 6.00 PKR, Remaining data 2,388.75 MB (Exp 25.03.2019), Main Account 7.62 PKR1500 PKR = 32GB valid 30 Days, Dial *477*32*1#. NumberingPlan=1 Nadi=4 UssdFormat=2 









    share|improve this question



























      0












      0








      0








      Need help if somebody kindly suggest how to extract the following values/fields from the text file in Linux system.



      EventCorrelationId="615-493|-1899671563||1550927718000"
      CreationTime="20190225094504"
      SubscriberNumber=92705073362


      Text file sample data is mentioned below:



      2019-02-25 09:45:04.427 FAIL RETRY: Failed for request id: 11235993 Cause: userNotReachable Info: <undef> Code: 27,USSD RequestId=11235993 OriginalId=11235993 EventCorrelationId="615-493|-1899671563||1550927718000" CreationTime="20190225094504" ResendCount=0 Timestamp=1551071704342 (Mon Feb 25 09:45:04 AFT 2019) State=STATE_SENT SubscriberNumber=92705073362 UssdText=Last event was charged 687.95 MB from 3GB Monthly, Main Account 6.00 PKR, Remaining data 2,388.75 MB (Exp 25.03.2019), Main Account 7.62 PKR1500 PKR = 32GB valid 30 Days, Dial *477*32*1#. NumberingPlan=1 Nadi=4 UssdFormat=2 









      share|improve this question
















      Need help if somebody kindly suggest how to extract the following values/fields from the text file in Linux system.



      EventCorrelationId="615-493|-1899671563||1550927718000"
      CreationTime="20190225094504"
      SubscriberNumber=92705073362


      Text file sample data is mentioned below:



      2019-02-25 09:45:04.427 FAIL RETRY: Failed for request id: 11235993 Cause: userNotReachable Info: <undef> Code: 27,USSD RequestId=11235993 OriginalId=11235993 EventCorrelationId="615-493|-1899671563||1550927718000" CreationTime="20190225094504" ResendCount=0 Timestamp=1551071704342 (Mon Feb 25 09:45:04 AFT 2019) State=STATE_SENT SubscriberNumber=92705073362 UssdText=Last event was charged 687.95 MB from 3GB Monthly, Main Account 6.00 PKR, Remaining data 2,388.75 MB (Exp 25.03.2019), Main Account 7.62 PKR1500 PKR = 32GB valid 30 Days, Dial *477*32*1#. NumberingPlan=1 Nadi=4 UssdFormat=2 






      linux shell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 34 mins ago









      John1024

      47.1k5110125




      47.1k5110125










      asked 50 mins ago









      Jack AndersonJack Anderson

      1




      1






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Using grep



          $ grep -oE '(EventCorrelationId|CreationTime|SubscriberNumber)[^ ]*' textfile
          EventCorrelationId="615-493|-1899671563||1550927718000"
          CreationTime="20190225094504"
          SubscriberNumber=92705073362


          Using awk



          Try:



          $ awk -v RS=' ' '/^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/' textfile
          EventCorrelationId="615-493|-1899671563||1550927718000"
          CreationTime="20190225094504"
          SubscriberNumber=92705073362


          How it works





          • -v RS=' '



            This tells awk to use a blank as the record separator.




          • /^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/



            This tells awk to print the record if it matches any of these three regular expressions. Some notes:




            • In a regex, ^ means beginning-of-the-record. Thus /^CreationTime=/ means a record that starts with CreationTime=


            • In awk, like many languages, || means logical-or. Thus ^EventCorrelationId=/ || /^CreationTime=/ is true if either regex is matched.





          Using sed



          $ sed -En 's/.*(EventCorrelationId=[^ ]*).*(CreationTime=[^ ]*).*(SubscriberNumber=[^ ]*).*/1n2n3/p' textfile
          EventCorrelationId="615-493|-1899671563||1550927718000"
          CreationTime="20190225094504"
          SubscriberNumber=92705073362





          share|improve this answer

































            0














            $ grep -Eo '(EventCorrelationId|CreationTime|SubscriberNumber)=[^ ]+' file
            EventCorrelationId="615-493|-1899671563||1550927718000"
            CreationTime="20190225094504"
            SubscriberNumber=92705073362




            • grep -Eo grep in extended regular expression mode (less escaping of special chars) and print only the matched parts


            • (EventCorrelationId|CreationTime|SubscriberNumber) match EventCorrelationId or CreationTime or SubscriberNumber


            • =[^ ]+ followed by "=", followed by non-space-character one or more times






            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',
              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%2f502782%2fhow-to-extract-specific-values-fields-from-the-text-file%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Using grep



              $ grep -oE '(EventCorrelationId|CreationTime|SubscriberNumber)[^ ]*' textfile
              EventCorrelationId="615-493|-1899671563||1550927718000"
              CreationTime="20190225094504"
              SubscriberNumber=92705073362


              Using awk



              Try:



              $ awk -v RS=' ' '/^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/' textfile
              EventCorrelationId="615-493|-1899671563||1550927718000"
              CreationTime="20190225094504"
              SubscriberNumber=92705073362


              How it works





              • -v RS=' '



                This tells awk to use a blank as the record separator.




              • /^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/



                This tells awk to print the record if it matches any of these three regular expressions. Some notes:




                • In a regex, ^ means beginning-of-the-record. Thus /^CreationTime=/ means a record that starts with CreationTime=


                • In awk, like many languages, || means logical-or. Thus ^EventCorrelationId=/ || /^CreationTime=/ is true if either regex is matched.





              Using sed



              $ sed -En 's/.*(EventCorrelationId=[^ ]*).*(CreationTime=[^ ]*).*(SubscriberNumber=[^ ]*).*/1n2n3/p' textfile
              EventCorrelationId="615-493|-1899671563||1550927718000"
              CreationTime="20190225094504"
              SubscriberNumber=92705073362





              share|improve this answer






























                0














                Using grep



                $ grep -oE '(EventCorrelationId|CreationTime|SubscriberNumber)[^ ]*' textfile
                EventCorrelationId="615-493|-1899671563||1550927718000"
                CreationTime="20190225094504"
                SubscriberNumber=92705073362


                Using awk



                Try:



                $ awk -v RS=' ' '/^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/' textfile
                EventCorrelationId="615-493|-1899671563||1550927718000"
                CreationTime="20190225094504"
                SubscriberNumber=92705073362


                How it works





                • -v RS=' '



                  This tells awk to use a blank as the record separator.




                • /^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/



                  This tells awk to print the record if it matches any of these three regular expressions. Some notes:




                  • In a regex, ^ means beginning-of-the-record. Thus /^CreationTime=/ means a record that starts with CreationTime=


                  • In awk, like many languages, || means logical-or. Thus ^EventCorrelationId=/ || /^CreationTime=/ is true if either regex is matched.





                Using sed



                $ sed -En 's/.*(EventCorrelationId=[^ ]*).*(CreationTime=[^ ]*).*(SubscriberNumber=[^ ]*).*/1n2n3/p' textfile
                EventCorrelationId="615-493|-1899671563||1550927718000"
                CreationTime="20190225094504"
                SubscriberNumber=92705073362





                share|improve this answer




























                  0












                  0








                  0







                  Using grep



                  $ grep -oE '(EventCorrelationId|CreationTime|SubscriberNumber)[^ ]*' textfile
                  EventCorrelationId="615-493|-1899671563||1550927718000"
                  CreationTime="20190225094504"
                  SubscriberNumber=92705073362


                  Using awk



                  Try:



                  $ awk -v RS=' ' '/^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/' textfile
                  EventCorrelationId="615-493|-1899671563||1550927718000"
                  CreationTime="20190225094504"
                  SubscriberNumber=92705073362


                  How it works





                  • -v RS=' '



                    This tells awk to use a blank as the record separator.




                  • /^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/



                    This tells awk to print the record if it matches any of these three regular expressions. Some notes:




                    • In a regex, ^ means beginning-of-the-record. Thus /^CreationTime=/ means a record that starts with CreationTime=


                    • In awk, like many languages, || means logical-or. Thus ^EventCorrelationId=/ || /^CreationTime=/ is true if either regex is matched.





                  Using sed



                  $ sed -En 's/.*(EventCorrelationId=[^ ]*).*(CreationTime=[^ ]*).*(SubscriberNumber=[^ ]*).*/1n2n3/p' textfile
                  EventCorrelationId="615-493|-1899671563||1550927718000"
                  CreationTime="20190225094504"
                  SubscriberNumber=92705073362





                  share|improve this answer















                  Using grep



                  $ grep -oE '(EventCorrelationId|CreationTime|SubscriberNumber)[^ ]*' textfile
                  EventCorrelationId="615-493|-1899671563||1550927718000"
                  CreationTime="20190225094504"
                  SubscriberNumber=92705073362


                  Using awk



                  Try:



                  $ awk -v RS=' ' '/^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/' textfile
                  EventCorrelationId="615-493|-1899671563||1550927718000"
                  CreationTime="20190225094504"
                  SubscriberNumber=92705073362


                  How it works





                  • -v RS=' '



                    This tells awk to use a blank as the record separator.




                  • /^EventCorrelationId=/ || /^CreationTime=/ || /^SubscriberNumber=/



                    This tells awk to print the record if it matches any of these three regular expressions. Some notes:




                    • In a regex, ^ means beginning-of-the-record. Thus /^CreationTime=/ means a record that starts with CreationTime=


                    • In awk, like many languages, || means logical-or. Thus ^EventCorrelationId=/ || /^CreationTime=/ is true if either regex is matched.





                  Using sed



                  $ sed -En 's/.*(EventCorrelationId=[^ ]*).*(CreationTime=[^ ]*).*(SubscriberNumber=[^ ]*).*/1n2n3/p' textfile
                  EventCorrelationId="615-493|-1899671563||1550927718000"
                  CreationTime="20190225094504"
                  SubscriberNumber=92705073362






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 25 mins ago

























                  answered 36 mins ago









                  John1024John1024

                  47.1k5110125




                  47.1k5110125

























                      0














                      $ grep -Eo '(EventCorrelationId|CreationTime|SubscriberNumber)=[^ ]+' file
                      EventCorrelationId="615-493|-1899671563||1550927718000"
                      CreationTime="20190225094504"
                      SubscriberNumber=92705073362




                      • grep -Eo grep in extended regular expression mode (less escaping of special chars) and print only the matched parts


                      • (EventCorrelationId|CreationTime|SubscriberNumber) match EventCorrelationId or CreationTime or SubscriberNumber


                      • =[^ ]+ followed by "=", followed by non-space-character one or more times






                      share|improve this answer




























                        0














                        $ grep -Eo '(EventCorrelationId|CreationTime|SubscriberNumber)=[^ ]+' file
                        EventCorrelationId="615-493|-1899671563||1550927718000"
                        CreationTime="20190225094504"
                        SubscriberNumber=92705073362




                        • grep -Eo grep in extended regular expression mode (less escaping of special chars) and print only the matched parts


                        • (EventCorrelationId|CreationTime|SubscriberNumber) match EventCorrelationId or CreationTime or SubscriberNumber


                        • =[^ ]+ followed by "=", followed by non-space-character one or more times






                        share|improve this answer


























                          0












                          0








                          0







                          $ grep -Eo '(EventCorrelationId|CreationTime|SubscriberNumber)=[^ ]+' file
                          EventCorrelationId="615-493|-1899671563||1550927718000"
                          CreationTime="20190225094504"
                          SubscriberNumber=92705073362




                          • grep -Eo grep in extended regular expression mode (less escaping of special chars) and print only the matched parts


                          • (EventCorrelationId|CreationTime|SubscriberNumber) match EventCorrelationId or CreationTime or SubscriberNumber


                          • =[^ ]+ followed by "=", followed by non-space-character one or more times






                          share|improve this answer













                          $ grep -Eo '(EventCorrelationId|CreationTime|SubscriberNumber)=[^ ]+' file
                          EventCorrelationId="615-493|-1899671563||1550927718000"
                          CreationTime="20190225094504"
                          SubscriberNumber=92705073362




                          • grep -Eo grep in extended regular expression mode (less escaping of special chars) and print only the matched parts


                          • (EventCorrelationId|CreationTime|SubscriberNumber) match EventCorrelationId or CreationTime or SubscriberNumber


                          • =[^ ]+ followed by "=", followed by non-space-character one or more times







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 21 mins ago









                          FreddyFreddy

                          6948




                          6948






























                              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%2f502782%2fhow-to-extract-specific-values-fields-from-the-text-file%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 rewrite equation of hyperbola in standard form

                              No ethernet ip address in my vocore2