unix awk match a string and perform delimiting












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
    22 hours ago










  • 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
    14 hours ago
















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
    22 hours ago










  • 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
    14 hours ago














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 14 hours ago









Emilio Galarraga

43929




43929










asked 22 hours ago









satsensort

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
    22 hours ago










  • 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
    14 hours ago


















  • 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
    22 hours ago










  • 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
    14 hours ago
















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
22 hours ago




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
22 hours ago












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
14 hours ago




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
14 hours ago










2 Answers
2






active

oldest

votes


















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 have GNU grep: grep -oP 'd+(?= packets received)'



    find the digits that are followed by " packets received"






    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

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      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 13 hours ago

























          answered 13 hours ago









          Larry

          1065




          1065

























              0














              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 have GNU grep: grep -oP 'd+(?= packets received)'



                find the digits that are followed by " packets received"






                share|improve this answer
























                  0












                  0








                  0






                  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 12 hours ago









                  glenn jackman

                  50.4k570107




                  50.4k570107






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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 make a Squid Proxy server?

                      Is this a new Fibonacci Identity?

                      19世紀