Copy specific text from one file to another

Multi tool use
Multi tool use

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











up vote
1
down vote

favorite
1












I have a text file that looks like this:



Start find in flight queries
2018-03-05 15:50:02,069:INFO:######################################
Start find completed queries
2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
2018-03-05 15:50:02,099:INFO:######################################
Start find in flight queries


The date and time changes every 5 minutes. I need to copy the very last date and time to another file. In this example its 2018-03-05 15:50:02.
Any suggestions are appreciated. I have used a little regex in the past but not good at it.







share|improve this question


























    up vote
    1
    down vote

    favorite
    1












    I have a text file that looks like this:



    Start find in flight queries
    2018-03-05 15:50:02,069:INFO:######################################
    Start find completed queries
    2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
    2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
    2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
    2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
    2018-03-05 15:50:02,099:INFO:######################################
    Start find in flight queries


    The date and time changes every 5 minutes. I need to copy the very last date and time to another file. In this example its 2018-03-05 15:50:02.
    Any suggestions are appreciated. I have used a little regex in the past but not good at it.







    share|improve this question
























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I have a text file that looks like this:



      Start find in flight queries
      2018-03-05 15:50:02,069:INFO:######################################
      Start find completed queries
      2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
      2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
      2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
      2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
      2018-03-05 15:50:02,099:INFO:######################################
      Start find in flight queries


      The date and time changes every 5 minutes. I need to copy the very last date and time to another file. In this example its 2018-03-05 15:50:02.
      Any suggestions are appreciated. I have used a little regex in the past but not good at it.







      share|improve this question














      I have a text file that looks like this:



      Start find in flight queries
      2018-03-05 15:50:02,069:INFO:######################################
      Start find completed queries
      2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
      2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
      2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
      2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
      2018-03-05 15:50:02,099:INFO:######################################
      Start find in flight queries


      The date and time changes every 5 minutes. I need to copy the very last date and time to another file. In this example its 2018-03-05 15:50:02.
      Any suggestions are appreciated. I have used a little regex in the past but not good at it.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 5 at 21:14

























      asked Mar 5 at 21:00









      user3508766

      447




      447




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          tac + grep solution:



          tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt





          share|improve this answer
















          • 1




            excellent! Is there something you used to help you figuring this out so quickly?
            – user3508766
            Mar 5 at 21:10










          • @user3508766, yes, I use my mind )
            – RomanPerekhrest
            Mar 5 at 21:11










          • haha very good, spasibo bolshoe
            – user3508766
            Mar 5 at 21:12










          • @user3508766, you are welcome!
            – RomanPerekhrest
            Mar 5 at 21:14

















          up vote
          1
          down vote













          Using awk without pipes ;)



          awk -F'[ ,]' '
          /^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
          var=$1" "$2
          ENDprint var
          ' file





          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%2f428367%2fcopy-specific-text-from-one-file-to-another%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
            2
            down vote



            accepted










            tac + grep solution:



            tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt





            share|improve this answer
















            • 1




              excellent! Is there something you used to help you figuring this out so quickly?
              – user3508766
              Mar 5 at 21:10










            • @user3508766, yes, I use my mind )
              – RomanPerekhrest
              Mar 5 at 21:11










            • haha very good, spasibo bolshoe
              – user3508766
              Mar 5 at 21:12










            • @user3508766, you are welcome!
              – RomanPerekhrest
              Mar 5 at 21:14














            up vote
            2
            down vote



            accepted










            tac + grep solution:



            tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt





            share|improve this answer
















            • 1




              excellent! Is there something you used to help you figuring this out so quickly?
              – user3508766
              Mar 5 at 21:10










            • @user3508766, yes, I use my mind )
              – RomanPerekhrest
              Mar 5 at 21:11










            • haha very good, spasibo bolshoe
              – user3508766
              Mar 5 at 21:12










            • @user3508766, you are welcome!
              – RomanPerekhrest
              Mar 5 at 21:14












            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            tac + grep solution:



            tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt





            share|improve this answer












            tac + grep solution:



            tac input.txt | grep -Eo -m1 '^[0-9]4(-[0-9]2)2 [0-9]2(:[0-9]2)2' > last_date.txt






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 5 at 21:06









            RomanPerekhrest

            22.4k12144




            22.4k12144







            • 1




              excellent! Is there something you used to help you figuring this out so quickly?
              – user3508766
              Mar 5 at 21:10










            • @user3508766, yes, I use my mind )
              – RomanPerekhrest
              Mar 5 at 21:11










            • haha very good, spasibo bolshoe
              – user3508766
              Mar 5 at 21:12










            • @user3508766, you are welcome!
              – RomanPerekhrest
              Mar 5 at 21:14












            • 1




              excellent! Is there something you used to help you figuring this out so quickly?
              – user3508766
              Mar 5 at 21:10










            • @user3508766, yes, I use my mind )
              – RomanPerekhrest
              Mar 5 at 21:11










            • haha very good, spasibo bolshoe
              – user3508766
              Mar 5 at 21:12










            • @user3508766, you are welcome!
              – RomanPerekhrest
              Mar 5 at 21:14







            1




            1




            excellent! Is there something you used to help you figuring this out so quickly?
            – user3508766
            Mar 5 at 21:10




            excellent! Is there something you used to help you figuring this out so quickly?
            – user3508766
            Mar 5 at 21:10












            @user3508766, yes, I use my mind )
            – RomanPerekhrest
            Mar 5 at 21:11




            @user3508766, yes, I use my mind )
            – RomanPerekhrest
            Mar 5 at 21:11












            haha very good, spasibo bolshoe
            – user3508766
            Mar 5 at 21:12




            haha very good, spasibo bolshoe
            – user3508766
            Mar 5 at 21:12












            @user3508766, you are welcome!
            – RomanPerekhrest
            Mar 5 at 21:14




            @user3508766, you are welcome!
            – RomanPerekhrest
            Mar 5 at 21:14












            up vote
            1
            down vote













            Using awk without pipes ;)



            awk -F'[ ,]' '
            /^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
            var=$1" "$2
            ENDprint var
            ' file





            share|improve this answer
























              up vote
              1
              down vote













              Using awk without pipes ;)



              awk -F'[ ,]' '
              /^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
              var=$1" "$2
              ENDprint var
              ' file





              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                Using awk without pipes ;)



                awk -F'[ ,]' '
                /^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
                var=$1" "$2
                ENDprint var
                ' file





                share|improve this answer












                Using awk without pipes ;)



                awk -F'[ ,]' '
                /^[0-9]4-[0-9]2-[0-9]2s+[0-9]2:[0-9]2:[0-9]2/
                var=$1" "$2
                ENDprint var
                ' file






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 5 at 21:30









                Gilles Quenot

                15.3k13448




                15.3k13448






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428367%2fcopy-specific-text-from-one-file-to-another%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    iMb4n,gnWWgbX RolRP 2sAWPM1RF75 oAtiU3UESqd iWTbzwIyS
                    LG6PFdaqkQga7LD3yt zxTQTx1ihQqLJDcbw ufOu,Vhv,YMMSmOKi3z5QjBUZGc XlXmTO9LUGeFz,Z

                    Popular posts from this blog

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

                    How many registers does an x86_64 CPU actually have?

                    Displaying single band from multi-band raster using QGIS