unix awk match a string and perform delimiting
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
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
add a comment |
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
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
awk sed ksh
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
If you have GNU grep: grep -oP 'd+(?= packets received)'
find the digits that are followed by " packets received"
add a comment |
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'"
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
If you have GNU grep: grep -oP 'd+(?= packets received)'
find the digits that are followed by " packets received"
add a comment |
If you have GNU grep: grep -oP 'd+(?= packets received)'
find the digits that are followed by " packets received"
add a comment |
If you have GNU grep: grep -oP 'd+(?= packets received)'
find the digits that are followed by " packets received"
If you have GNU grep: grep -oP 'd+(?= packets received)'
find the digits that are followed by " packets received"
answered Jan 4 at 16:09
glenn jackmanglenn jackman
50.9k571109
50.9k571109
add a comment |
add a comment |
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'"
add a comment |
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'"
add a comment |
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'"
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'"
edited Jan 4 at 15:59
answered Jan 4 at 15:44
LarryLarry
1165
1165
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Jan 9 at 18:33
Praveen Kumar BSPraveen Kumar BS
1,340138
1,340138
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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