Get one thing from a line and concatenate it with one thing from another line










4















I have the following:



2018-11-10 23:57:21 [COMMAND]: sar -u 10 5

AIX host 1 7 11/10/18

System configuration: lcpu=64 mode=Capped

23:57:21 %usr %sys %wio %idle physc
23:57:31 10 7 0 83 16.00
23:57:41 9 6 0 85 16.00
23:57:51 9 6 0 85 16.00
23:58:01 9 7 0 84 16.00
23:58:11 10 6 0 84 16.00

Average 9 6 0 84 16.00

2018-11-10 23:58:21 [COMMAND]: sar -u 10 5

AIX host 1 7 11/10/18

System configuration: lcpu=64 mode=Capped

23:58:21 %usr %sys %wio %idle physc
23:58:31 10 8 0 82 15.99
23:58:41 9 6 0 85 16.00
23:58:51 9 6 0 85 16.00
23:59:01 9 6 0 84 16.00
23:59:11 10 6 0 83 16.00

Average 10 6 0 84 16.00


I need to get the time with the average value of %idle:



2018-11-10 23:57:21|84
2018-11-10 23:58:21|84









share|improve this question
























  • actually i am getting this file from another server and it is only one file

    – ammar
    Nov 11 '18 at 13:12






  • 1





    This is using this site as a script-writing service.

    – Peter Mortensen
    Nov 12 '18 at 8:30















4















I have the following:



2018-11-10 23:57:21 [COMMAND]: sar -u 10 5

AIX host 1 7 11/10/18

System configuration: lcpu=64 mode=Capped

23:57:21 %usr %sys %wio %idle physc
23:57:31 10 7 0 83 16.00
23:57:41 9 6 0 85 16.00
23:57:51 9 6 0 85 16.00
23:58:01 9 7 0 84 16.00
23:58:11 10 6 0 84 16.00

Average 9 6 0 84 16.00

2018-11-10 23:58:21 [COMMAND]: sar -u 10 5

AIX host 1 7 11/10/18

System configuration: lcpu=64 mode=Capped

23:58:21 %usr %sys %wio %idle physc
23:58:31 10 8 0 82 15.99
23:58:41 9 6 0 85 16.00
23:58:51 9 6 0 85 16.00
23:59:01 9 6 0 84 16.00
23:59:11 10 6 0 83 16.00

Average 10 6 0 84 16.00


I need to get the time with the average value of %idle:



2018-11-10 23:57:21|84
2018-11-10 23:58:21|84









share|improve this question
























  • actually i am getting this file from another server and it is only one file

    – ammar
    Nov 11 '18 at 13:12






  • 1





    This is using this site as a script-writing service.

    – Peter Mortensen
    Nov 12 '18 at 8:30













4












4








4








I have the following:



2018-11-10 23:57:21 [COMMAND]: sar -u 10 5

AIX host 1 7 11/10/18

System configuration: lcpu=64 mode=Capped

23:57:21 %usr %sys %wio %idle physc
23:57:31 10 7 0 83 16.00
23:57:41 9 6 0 85 16.00
23:57:51 9 6 0 85 16.00
23:58:01 9 7 0 84 16.00
23:58:11 10 6 0 84 16.00

Average 9 6 0 84 16.00

2018-11-10 23:58:21 [COMMAND]: sar -u 10 5

AIX host 1 7 11/10/18

System configuration: lcpu=64 mode=Capped

23:58:21 %usr %sys %wio %idle physc
23:58:31 10 8 0 82 15.99
23:58:41 9 6 0 85 16.00
23:58:51 9 6 0 85 16.00
23:59:01 9 6 0 84 16.00
23:59:11 10 6 0 83 16.00

Average 10 6 0 84 16.00


I need to get the time with the average value of %idle:



2018-11-10 23:57:21|84
2018-11-10 23:58:21|84









share|improve this question
















I have the following:



2018-11-10 23:57:21 [COMMAND]: sar -u 10 5

AIX host 1 7 11/10/18

System configuration: lcpu=64 mode=Capped

23:57:21 %usr %sys %wio %idle physc
23:57:31 10 7 0 83 16.00
23:57:41 9 6 0 85 16.00
23:57:51 9 6 0 85 16.00
23:58:01 9 7 0 84 16.00
23:58:11 10 6 0 84 16.00

Average 9 6 0 84 16.00

2018-11-10 23:58:21 [COMMAND]: sar -u 10 5

AIX host 1 7 11/10/18

System configuration: lcpu=64 mode=Capped

23:58:21 %usr %sys %wio %idle physc
23:58:31 10 8 0 82 15.99
23:58:41 9 6 0 85 16.00
23:58:51 9 6 0 85 16.00
23:59:01 9 6 0 84 16.00
23:59:11 10 6 0 83 16.00

Average 10 6 0 84 16.00


I need to get the time with the average value of %idle:



2018-11-10 23:57:21|84
2018-11-10 23:58:21|84






text-processing awk sed perl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 9:07









Peter Mortensen

90158




90158










asked Nov 11 '18 at 13:02









ammarammar

357




357












  • actually i am getting this file from another server and it is only one file

    – ammar
    Nov 11 '18 at 13:12






  • 1





    This is using this site as a script-writing service.

    – Peter Mortensen
    Nov 12 '18 at 8:30

















  • actually i am getting this file from another server and it is only one file

    – ammar
    Nov 11 '18 at 13:12






  • 1





    This is using this site as a script-writing service.

    – Peter Mortensen
    Nov 12 '18 at 8:30
















actually i am getting this file from another server and it is only one file

– ammar
Nov 11 '18 at 13:12





actually i am getting this file from another server and it is only one file

– ammar
Nov 11 '18 at 13:12




1




1





This is using this site as a script-writing service.

– Peter Mortensen
Nov 12 '18 at 8:30





This is using this site as a script-writing service.

– Peter Mortensen
Nov 12 '18 at 8:30










3 Answers
3






active

oldest

votes


















11














Going by your input file as-is, a simple awk command as simple as below should suffice.



awk '/sar/ time=$1" "$2; next /Average/ print time"' file





share|improve this answer






























    5














    A couple of choices:




    • awk



      $ awk '/COMMAND/printf "%s %s", $1,$2/Average/"$5' file 
      2018-11-10 23:57:21|84
      2018-11-10 23:58:21|84



    • perl



      $ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file 
      2018-11-10 23:57:21|84
      2018-11-10 23:58:21|84






    share|improve this answer
































      2














      This Perl one-liner should do the trick:



      perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
      if(/^Averages+S+s+S+s+S+s+(S+)/) $1";'


      (I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name at the beginning or the end, or a pipe will do. The workings are these:



      1. Go to a line with date and time at the beginning and memorise it.

      2. Go to a line with Average at beginning and once there, print the memorised date and time plus the | sign and the average taken from the fifth column assuming whitespace column separation.

      3. Point 1. repeats.





      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%2f481082%2fget-one-thing-from-a-line-and-concatenate-it-with-one-thing-from-another-line%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        11














        Going by your input file as-is, a simple awk command as simple as below should suffice.



        awk '/sar/ time=$1" "$2; next /Average/ print time"' file





        share|improve this answer



























          11














          Going by your input file as-is, a simple awk command as simple as below should suffice.



          awk '/sar/ time=$1" "$2; next /Average/ print time"' file





          share|improve this answer

























            11












            11








            11







            Going by your input file as-is, a simple awk command as simple as below should suffice.



            awk '/sar/ time=$1" "$2; next /Average/ print time"' file





            share|improve this answer













            Going by your input file as-is, a simple awk command as simple as below should suffice.



            awk '/sar/ time=$1" "$2; next /Average/ print time"' file






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 11 '18 at 13:16









            InianInian

            4,110824




            4,110824























                5














                A couple of choices:




                • awk



                  $ awk '/COMMAND/printf "%s %s", $1,$2/Average/"$5' file 
                  2018-11-10 23:57:21|84
                  2018-11-10 23:58:21|84



                • perl



                  $ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file 
                  2018-11-10 23:57:21|84
                  2018-11-10 23:58:21|84






                share|improve this answer





























                  5














                  A couple of choices:




                  • awk



                    $ awk '/COMMAND/printf "%s %s", $1,$2/Average/"$5' file 
                    2018-11-10 23:57:21|84
                    2018-11-10 23:58:21|84



                  • perl



                    $ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file 
                    2018-11-10 23:57:21|84
                    2018-11-10 23:58:21|84






                  share|improve this answer



























                    5












                    5








                    5







                    A couple of choices:




                    • awk



                      $ awk '/COMMAND/printf "%s %s", $1,$2/Average/"$5' file 
                      2018-11-10 23:57:21|84
                      2018-11-10 23:58:21|84



                    • perl



                      $ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file 
                      2018-11-10 23:57:21|84
                      2018-11-10 23:58:21|84






                    share|improve this answer















                    A couple of choices:




                    • awk



                      $ awk '/COMMAND/printf "%s %s", $1,$2/Average/"$5' file 
                      2018-11-10 23:57:21|84
                      2018-11-10 23:58:21|84



                    • perl



                      $ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file 
                      2018-11-10 23:57:21|84
                      2018-11-10 23:58:21|84







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 11 '18 at 16:19

























                    answered Nov 11 '18 at 14:48









                    terdonterdon

                    130k32255433




                    130k32255433





















                        2














                        This Perl one-liner should do the trick:



                        perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
                        if(/^Averages+S+s+S+s+S+s+(S+)/) $1";'


                        (I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name at the beginning or the end, or a pipe will do. The workings are these:



                        1. Go to a line with date and time at the beginning and memorise it.

                        2. Go to a line with Average at beginning and once there, print the memorised date and time plus the | sign and the average taken from the fifth column assuming whitespace column separation.

                        3. Point 1. repeats.





                        share|improve this answer





























                          2














                          This Perl one-liner should do the trick:



                          perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
                          if(/^Averages+S+s+S+s+S+s+(S+)/) $1";'


                          (I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name at the beginning or the end, or a pipe will do. The workings are these:



                          1. Go to a line with date and time at the beginning and memorise it.

                          2. Go to a line with Average at beginning and once there, print the memorised date and time plus the | sign and the average taken from the fifth column assuming whitespace column separation.

                          3. Point 1. repeats.





                          share|improve this answer



























                            2












                            2








                            2







                            This Perl one-liner should do the trick:



                            perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
                            if(/^Averages+S+s+S+s+S+s+(S+)/) $1";'


                            (I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name at the beginning or the end, or a pipe will do. The workings are these:



                            1. Go to a line with date and time at the beginning and memorise it.

                            2. Go to a line with Average at beginning and once there, print the memorised date and time plus the | sign and the average taken from the fifth column assuming whitespace column separation.

                            3. Point 1. repeats.





                            share|improve this answer















                            This Perl one-liner should do the trick:



                            perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
                            if(/^Averages+S+s+S+s+S+s+(S+)/) $1";'


                            (I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name at the beginning or the end, or a pipe will do. The workings are these:



                            1. Go to a line with date and time at the beginning and memorise it.

                            2. Go to a line with Average at beginning and once there, print the memorised date and time plus the | sign and the average taken from the fifth column assuming whitespace column separation.

                            3. Point 1. repeats.






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 11 '18 at 13:23

























                            answered Nov 11 '18 at 13:15









                            TomaszTomasz

                            9,53652965




                            9,53652965



























                                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%2f481082%2fget-one-thing-from-a-line-and-concatenate-it-with-one-thing-from-another-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

                                𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                                Crossroads (UK TV series)

                                ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế