How to extract specific values/fields from the text file?Extract information from a text fileHow can I...

Is there any way to make an Apex method parameter lazy?

How to create a label containing values from different layers in QGIS

How can I give a Ranger advantage on a check due to Favored Enemy without spoiling the story for the player?

Is `Object` a function in javascript?

Eww, those bytes are gross

Renting a 2CV in France

Illustrator to chemdraw

Writing dialogues for characters whose first language is not English

How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?

What does からか mean?

What species should be used for storage of human minds?

Icon at Subject-line scrlttr2

Why is this column order in my non-clustered index better for my query?

Critique vs nitpicking

Modern Algebraic Geometry and Analytic Number Theory

Potential client has a problematic employee I can't work with

How to deal with an underperforming subordinate?

Website seeing my Facebook data?

Boss asked me to sign a resignation paper without a date on it along with my new contract

Charging phone battery with a lower voltage, coming from a bike charger?

Why did Ylvis use "go" instead of "say" in phrases like "Dog goes 'woof'"?

Count repetitions of an array

How to change a .eps figure to standalone class?

How to write cases in LaTeX?



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


Extract information from a text fileHow can I extract a specific string from a file?Extract text between two specific linesExtract values from HTML FilesExtract Values from Formatted TextSubstitute text fields with values from other fileText processing to extract structure fieldsText substitution with specific fields in a log file.filter specific text from file?How do I add additional fields to a text file from another text file with some matching fields?













4















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





























    4















    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



























      4












      4








      4








      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
















      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 






      text-processing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      terdon

      131k32257436




      131k32257436










      asked 8 hours ago









      Jack AndersonJack Anderson

      232




      232






















          2 Answers
          2






          active

          oldest

          votes


















          3














          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


          Using an alternate separator in the output



          To use | as the output separator in place of newline:



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





          share|improve this answer

































            2














            $ 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


            Edit:



            Now separated by "|":



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





            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









              3














              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


              Using an alternate separator in the output



              To use | as the output separator in place of newline:



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





              share|improve this answer






























                3














                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


                Using an alternate separator in the output



                To use | as the output separator in place of newline:



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





                share|improve this answer




























                  3












                  3








                  3







                  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


                  Using an alternate separator in the output



                  To use | as the output separator in place of newline:



                  $ sed -En 's/.*(EventCorrelationId=[^ ]*).*(CreationTime=[^ ]*).*(SubscriberNumber=[^ ]*).*/1|2|3/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


                  Using an alternate separator in the output



                  To use | as the output separator in place of newline:



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






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 6 hours ago

























                  answered 8 hours ago









                  John1024John1024

                  47.2k5110125




                  47.2k5110125

























                      2














                      $ 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


                      Edit:



                      Now separated by "|":



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





                      share|improve this answer






























                        2














                        $ 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


                        Edit:



                        Now separated by "|":



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





                        share|improve this answer




























                          2












                          2








                          2







                          $ 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


                          Edit:



                          Now separated by "|":



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





                          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


                          Edit:



                          Now separated by "|":



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






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 6 hours ago

























                          answered 8 hours ago









                          FreddyFreddy

                          7398




                          7398






























                              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

                              Why do type traits not work with types in namespace scope?What are POD types in C++?Why can templates only be...

                              Will tsunami waves travel forever if there was no land?Why do tsunami waves begin with the water flowing away...

                              Simple Scan not detecting my scanner (Brother DCP-7055W)Brother MFC-L2700DW printer can print, can't...