unix awk match a string and perform delimiting

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












0















I'm checking the ping connectivity checks from a host and that would ssh to another jump host and will perform ping communication. I would like to print the successful packets pinged count using awk.



xajvtl001:/home/root #ssh -qn xckvl002"ping -w2 -c3 xcvtc012| grep packets"
3 packets transmitted, 3 packets received, 0% packet loss


Expected output value is 3 from the packet received count.










share|improve this question
























  • i tried ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 grep "packets received" | cut -d "," -f2 | cut -d " " -f2" It doesnt provide any results on the SSH. But i can get the result when im logging into the jumphost and run the ping command without SSH.

    – satsensort
    Jan 4 at 6:19











  • please edit the question and add the full command to the question. I think you're missing a |, and you have some issues with quoting...

    – RoVo
    Jan 4 at 14:51















0















I'm checking the ping connectivity checks from a host and that would ssh to another jump host and will perform ping communication. I would like to print the successful packets pinged count using awk.



xajvtl001:/home/root #ssh -qn xckvl002"ping -w2 -c3 xcvtc012| grep packets"
3 packets transmitted, 3 packets received, 0% packet loss


Expected output value is 3 from the packet received count.










share|improve this question
























  • i tried ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 grep "packets received" | cut -d "," -f2 | cut -d " " -f2" It doesnt provide any results on the SSH. But i can get the result when im logging into the jumphost and run the ping command without SSH.

    – satsensort
    Jan 4 at 6:19











  • please edit the question and add the full command to the question. I think you're missing a |, and you have some issues with quoting...

    – RoVo
    Jan 4 at 14:51













0












0








0








I'm checking the ping connectivity checks from a host and that would ssh to another jump host and will perform ping communication. I would like to print the successful packets pinged count using awk.



xajvtl001:/home/root #ssh -qn xckvl002"ping -w2 -c3 xcvtc012| grep packets"
3 packets transmitted, 3 packets received, 0% packet loss


Expected output value is 3 from the packet received count.










share|improve this question
















I'm checking the ping connectivity checks from a host and that would ssh to another jump host and will perform ping communication. I would like to print the successful packets pinged count using awk.



xajvtl001:/home/root #ssh -qn xckvl002"ping -w2 -c3 xcvtc012| grep packets"
3 packets transmitted, 3 packets received, 0% packet loss


Expected output value is 3 from the packet received count.







awk sed ksh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 14:43









Emilio Galarraga

50929




50929










asked Jan 4 at 6:17









satsensortsatsensort

248




248












  • i tried ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 grep "packets received" | cut -d "," -f2 | cut -d " " -f2" It doesnt provide any results on the SSH. But i can get the result when im logging into the jumphost and run the ping command without SSH.

    – satsensort
    Jan 4 at 6:19











  • please edit the question and add the full command to the question. I think you're missing a |, and you have some issues with quoting...

    – RoVo
    Jan 4 at 14:51

















  • i tried ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 grep "packets received" | cut -d "," -f2 | cut -d " " -f2" It doesnt provide any results on the SSH. But i can get the result when im logging into the jumphost and run the ping command without SSH.

    – satsensort
    Jan 4 at 6:19











  • please edit the question and add the full command to the question. I think you're missing a |, and you have some issues with quoting...

    – RoVo
    Jan 4 at 14:51
















i tried ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 grep "packets received" | cut -d "," -f2 | cut -d " " -f2" It doesnt provide any results on the SSH. But i can get the result when im logging into the jumphost and run the ping command without SSH.

– satsensort
Jan 4 at 6:19





i tried ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 grep "packets received" | cut -d "," -f2 | cut -d " " -f2" It doesnt provide any results on the SSH. But i can get the result when im logging into the jumphost and run the ping command without SSH.

– satsensort
Jan 4 at 6:19













please edit the question and add the full command to the question. I think you're missing a |, and you have some issues with quoting...

– RoVo
Jan 4 at 14:51





please edit the question and add the full command to the question. I think you're missing a |, and you have some issues with quoting...

– RoVo
Jan 4 at 14:51










3 Answers
3






active

oldest

votes


















1














If you have GNU grep: grep -oP 'd+(?= packets received)'



find the digits that are followed by " packets received"






share|improve this answer






























    0














    If you are looking for the number of packets received:



    ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | awk '/packets transmitted,/ print $4'"



    Since you are using double quotes around the remote command, the inner single quotes lose their immediate quoting meaning, and thus characters like $ still need escaping. This is the reason for the backslash in print $4.



    Note that implementations of ping can have different output.
    In my case for instance, N packets received is Received = N instead. You might want to take care in making sure the search pattern, which is enclosed in slashes in my awk example, correctly identify the summary line.
    Also, if there is a different number of whitespace-delimited fields in your output, you might have to use a different number than 4 for the $4 field variable.



    EDIT: A solution using sed for those who are interested:



    ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | sed -nr 's/.*([0-9]+)s*received,.*/1/p'"






    share|improve this answer
































      0














      I have used below command to find



      en_linux_example j1]# ping -c3 hostname|awk '/received/print $0'| awk -F "," 'print $2'|sed -r "s/^s+//g"| awk 'print $1'



      output
      3





      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%2f492391%2funix-awk-match-a-string-and-perform-delimiting%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









        1














        If you have GNU grep: grep -oP 'd+(?= packets received)'



        find the digits that are followed by " packets received"






        share|improve this answer



























          1














          If you have GNU grep: grep -oP 'd+(?= packets received)'



          find the digits that are followed by " packets received"






          share|improve this answer

























            1












            1








            1







            If you have GNU grep: grep -oP 'd+(?= packets received)'



            find the digits that are followed by " packets received"






            share|improve this answer













            If you have GNU grep: grep -oP 'd+(?= packets received)'



            find the digits that are followed by " packets received"







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 4 at 16:09









            glenn jackmanglenn jackman

            50.9k571109




            50.9k571109























                0














                If you are looking for the number of packets received:



                ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | awk '/packets transmitted,/ print $4'"



                Since you are using double quotes around the remote command, the inner single quotes lose their immediate quoting meaning, and thus characters like $ still need escaping. This is the reason for the backslash in print $4.



                Note that implementations of ping can have different output.
                In my case for instance, N packets received is Received = N instead. You might want to take care in making sure the search pattern, which is enclosed in slashes in my awk example, correctly identify the summary line.
                Also, if there is a different number of whitespace-delimited fields in your output, you might have to use a different number than 4 for the $4 field variable.



                EDIT: A solution using sed for those who are interested:



                ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | sed -nr 's/.*([0-9]+)s*received,.*/1/p'"






                share|improve this answer





























                  0














                  If you are looking for the number of packets received:



                  ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | awk '/packets transmitted,/ print $4'"



                  Since you are using double quotes around the remote command, the inner single quotes lose their immediate quoting meaning, and thus characters like $ still need escaping. This is the reason for the backslash in print $4.



                  Note that implementations of ping can have different output.
                  In my case for instance, N packets received is Received = N instead. You might want to take care in making sure the search pattern, which is enclosed in slashes in my awk example, correctly identify the summary line.
                  Also, if there is a different number of whitespace-delimited fields in your output, you might have to use a different number than 4 for the $4 field variable.



                  EDIT: A solution using sed for those who are interested:



                  ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | sed -nr 's/.*([0-9]+)s*received,.*/1/p'"






                  share|improve this answer



























                    0












                    0








                    0







                    If you are looking for the number of packets received:



                    ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | awk '/packets transmitted,/ print $4'"



                    Since you are using double quotes around the remote command, the inner single quotes lose their immediate quoting meaning, and thus characters like $ still need escaping. This is the reason for the backslash in print $4.



                    Note that implementations of ping can have different output.
                    In my case for instance, N packets received is Received = N instead. You might want to take care in making sure the search pattern, which is enclosed in slashes in my awk example, correctly identify the summary line.
                    Also, if there is a different number of whitespace-delimited fields in your output, you might have to use a different number than 4 for the $4 field variable.



                    EDIT: A solution using sed for those who are interested:



                    ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | sed -nr 's/.*([0-9]+)s*received,.*/1/p'"






                    share|improve this answer















                    If you are looking for the number of packets received:



                    ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | awk '/packets transmitted,/ print $4'"



                    Since you are using double quotes around the remote command, the inner single quotes lose their immediate quoting meaning, and thus characters like $ still need escaping. This is the reason for the backslash in print $4.



                    Note that implementations of ping can have different output.
                    In my case for instance, N packets received is Received = N instead. You might want to take care in making sure the search pattern, which is enclosed in slashes in my awk example, correctly identify the summary line.
                    Also, if there is a different number of whitespace-delimited fields in your output, you might have to use a different number than 4 for the $4 field variable.



                    EDIT: A solution using sed for those who are interested:



                    ssh -qn xckvl002 "ping -w2 -c3 xcvtc012 | sed -nr 's/.*([0-9]+)s*received,.*/1/p'"







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 4 at 15:59

























                    answered Jan 4 at 15:44









                    LarryLarry

                    1165




                    1165





















                        0














                        I have used below command to find



                        en_linux_example j1]# ping -c3 hostname|awk '/received/print $0'| awk -F "," 'print $2'|sed -r "s/^s+//g"| awk 'print $1'



                        output
                        3





                        share|improve this answer



























                          0














                          I have used below command to find



                          en_linux_example j1]# ping -c3 hostname|awk '/received/print $0'| awk -F "," 'print $2'|sed -r "s/^s+//g"| awk 'print $1'



                          output
                          3





                          share|improve this answer

























                            0












                            0








                            0







                            I have used below command to find



                            en_linux_example j1]# ping -c3 hostname|awk '/received/print $0'| awk -F "," 'print $2'|sed -r "s/^s+//g"| awk 'print $1'



                            output
                            3





                            share|improve this answer













                            I have used below command to find



                            en_linux_example j1]# ping -c3 hostname|awk '/received/print $0'| awk -F "," 'print $2'|sed -r "s/^s+//g"| awk 'print $1'



                            output
                            3






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 9 at 18:33









                            Praveen Kumar BSPraveen Kumar BS

                            1,340138




                            1,340138



























                                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%2f492391%2funix-awk-match-a-string-and-perform-delimiting%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 check contact read email or not when send email to Individual?

                                Displaying single band from multi-band raster using QGIS

                                How many registers does an x86_64 CPU actually have?