Can I run two different awk commands in 1
up vote
0
down vote
favorite
I can use this awk command to get last line of log file:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log
And I can use this awk command to extract a substring:
awk -F"[()]" '{print $2}' /home/jj1/.pia_manager/log/pia_nw.log
What i'd like to do is combine the two into one awk command. I've tried many combinations but can't get it to work. My goal is to send extracted string to Conky display. Can this be done, or do I need to use 2 commands?
Last line in log file always has string I need:
[2018-11-15T03:34:07.160Z] <debug> |tray| Translated status is "You are connected (Canada Vancouver)"
The part in parenthesis is what I want.
Resulting output:
Canada Vancouver
command-line text-processing awk
add a comment |
up vote
0
down vote
favorite
I can use this awk command to get last line of log file:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log
And I can use this awk command to extract a substring:
awk -F"[()]" '{print $2}' /home/jj1/.pia_manager/log/pia_nw.log
What i'd like to do is combine the two into one awk command. I've tried many combinations but can't get it to work. My goal is to send extracted string to Conky display. Can this be done, or do I need to use 2 commands?
Last line in log file always has string I need:
[2018-11-15T03:34:07.160Z] <debug> |tray| Translated status is "You are connected (Canada Vancouver)"
The part in parenthesis is what I want.
Resulting output:
Canada Vancouver
command-line text-processing awk
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I can use this awk command to get last line of log file:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log
And I can use this awk command to extract a substring:
awk -F"[()]" '{print $2}' /home/jj1/.pia_manager/log/pia_nw.log
What i'd like to do is combine the two into one awk command. I've tried many combinations but can't get it to work. My goal is to send extracted string to Conky display. Can this be done, or do I need to use 2 commands?
Last line in log file always has string I need:
[2018-11-15T03:34:07.160Z] <debug> |tray| Translated status is "You are connected (Canada Vancouver)"
The part in parenthesis is what I want.
Resulting output:
Canada Vancouver
command-line text-processing awk
I can use this awk command to get last line of log file:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log
And I can use this awk command to extract a substring:
awk -F"[()]" '{print $2}' /home/jj1/.pia_manager/log/pia_nw.log
What i'd like to do is combine the two into one awk command. I've tried many combinations but can't get it to work. My goal is to send extracted string to Conky display. Can this be done, or do I need to use 2 commands?
Last line in log file always has string I need:
[2018-11-15T03:34:07.160Z] <debug> |tray| Translated status is "You are connected (Canada Vancouver)"
The part in parenthesis is what I want.
Resulting output:
Canada Vancouver
command-line text-processing awk
command-line text-processing awk
edited 2 days ago
muru
133k19282479
133k19282479
asked Nov 15 at 6:44
jj1
115
115
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
If you want the second field of the last line using that field separator:
awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log
muru Thank you for your solution. It's exactly what I was after.
– jj1
2 days ago
add a comment |
up vote
0
down vote
Pipe the output of the first awk to the second awk:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
This variant is more safe (ignore last empty lines in file):
awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
@ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
– jj1
Nov 15 at 7:14
The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
– jj1
Nov 15 at 7:24
Yes, last non empty line. Also fixed second example containing your previous comment
– S_Flash
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
If you want the second field of the last line using that field separator:
awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log
muru Thank you for your solution. It's exactly what I was after.
– jj1
2 days ago
add a comment |
up vote
1
down vote
If you want the second field of the last line using that field separator:
awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log
muru Thank you for your solution. It's exactly what I was after.
– jj1
2 days ago
add a comment |
up vote
1
down vote
up vote
1
down vote
If you want the second field of the last line using that field separator:
awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log
If you want the second field of the last line using that field separator:
awk -F"[()]" 'END {print $2}' /home/jj1/.pia_manager/log/pia_nw.log
answered 2 days ago
muru
133k19282479
133k19282479
muru Thank you for your solution. It's exactly what I was after.
– jj1
2 days ago
add a comment |
muru Thank you for your solution. It's exactly what I was after.
– jj1
2 days ago
muru Thank you for your solution. It's exactly what I was after.
– jj1
2 days ago
muru Thank you for your solution. It's exactly what I was after.
– jj1
2 days ago
add a comment |
up vote
0
down vote
Pipe the output of the first awk to the second awk:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
This variant is more safe (ignore last empty lines in file):
awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
@ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
– jj1
Nov 15 at 7:14
The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
– jj1
Nov 15 at 7:24
Yes, last non empty line. Also fixed second example containing your previous comment
– S_Flash
2 days ago
add a comment |
up vote
0
down vote
Pipe the output of the first awk to the second awk:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
This variant is more safe (ignore last empty lines in file):
awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
@ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
– jj1
Nov 15 at 7:14
The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
– jj1
Nov 15 at 7:24
Yes, last non empty line. Also fixed second example containing your previous comment
– S_Flash
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
Pipe the output of the first awk to the second awk:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
This variant is more safe (ignore last empty lines in file):
awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
Pipe the output of the first awk to the second awk:
awk 'END{print}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
This variant is more safe (ignore last empty lines in file):
awk '/^$/ {nlstack=nlstack "n";next;} END{printf "%s",nlstack; nlstack=""; print;}' /home/jj1/.pia_manager/log/pia_nw.log | awk -F"[()]" '{print $2}'
edited 2 days ago
answered Nov 15 at 6:55
S_Flash
858117
858117
@ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
– jj1
Nov 15 at 7:14
The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
– jj1
Nov 15 at 7:24
Yes, last non empty line. Also fixed second example containing your previous comment
– S_Flash
2 days ago
add a comment |
@ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
– jj1
Nov 15 at 7:14
The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
– jj1
Nov 15 at 7:24
Yes, last non empty line. Also fixed second example containing your previous comment
– S_Flash
2 days ago
@ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
– jj1
Nov 15 at 7:14
@ S_Flash-I was thinking that the 2 could be nested in a way that it would use only 1 instance of awk, but thanks. That works fine.
– jj1
Nov 15 at 7:14
The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
– jj1
Nov 15 at 7:24
The line I need to extract from will always be the last. Are you saying there could be empty lines below that?
– jj1
Nov 15 at 7:24
Yes, last non empty line. Also fixed second example containing your previous comment
– S_Flash
2 days ago
Yes, last non empty line. Also fixed second example containing your previous comment
– S_Flash
2 days ago
add a comment |
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%2faskubuntu.com%2fquestions%2f1093075%2fcan-i-run-two-different-awk-commands-in-1%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