how to get multiple command output as variable in awk
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to execute 3 command and get the output as a variable which needs some percentage calculation and display the same as the example. can this be executed as script.
First command output
$ isi status -q | grep -e "^Size" -e "^Used" -e "^Avail"
Size:573T
Used:448.0T
Avail:74T
Second command output
$ isi_classic snapshot usage | tail -n 1 | awk 'printf "tttSnapshot USED %=%.1f%%n", $4'
Snapshot USED =0.6%
$ isi_classic snapshot usage | tail -n -1 | awk ' print "tttSnapshot USED:" $1'
Snapshot USED=3.2T
example script awk script not working. after removed space
# isi status -q | grep -e "^Size" -e "^Used" -e "^Avail" | awk 'function print (num)
pipe pipe quote> /Size:/ TotalSize=$NF~
pipe pipe quote> /Used:/ TotalUsed=$NF
pipe pipe quote> /Avail:/ TotalAvail=$NF }
pipe pipe quote> END awk 'printf "Snapshot_per :%.1fn", $4'")
pipe pipe quote> Usedw/o=Total Used-Snapshot USED/Total Size
pipe pipe quote> print hostname ": " "t","Total Size:" Total_Size
pipe pipe quote> printf "tttTotalUsed:%.1fn", TotalUsed, "TB"
pipe pipe quote> printf "tttTotalAvail:%.1fn", TotalAvail, "TB"
pipe pipe quote> printf "tttTotalUsed %:%.1fn", used, "TB"
pipe pipe quote> printf "tttSnapshot Used :%.1fn", Snapshot_used, "TB"
pipe pipe quote> printf "tttSnapshot Used %:%.1fn", Snapshot_per, "TB"
pipe pipe quote> printf "tttUsed w/o:%.1fn", Usedw/o, TB)'
awk: syntax error at source line 1
context is
function >>> print <<< (num)
missing
missing )
awk: bailing out at source line 7
Sample Requirement
Total Size : 573 TB
Total Used : 448.0 TB
Total Available : 74 TB
Total Used % : 86.1 % # Total Used(%) = Total Used/Total Size *100 = 86.1(%)
Snapshot Used : 3.2 TB
Snapshot Used % : 0.6 %
Used w/o : 85.5 % # (Total used)-(Snapshot used) / (Total size) = 85.49%
shell-script awk scripting gawk
add a comment |Â
up vote
0
down vote
favorite
I am trying to execute 3 command and get the output as a variable which needs some percentage calculation and display the same as the example. can this be executed as script.
First command output
$ isi status -q | grep -e "^Size" -e "^Used" -e "^Avail"
Size:573T
Used:448.0T
Avail:74T
Second command output
$ isi_classic snapshot usage | tail -n 1 | awk 'printf "tttSnapshot USED %=%.1f%%n", $4'
Snapshot USED =0.6%
$ isi_classic snapshot usage | tail -n -1 | awk ' print "tttSnapshot USED:" $1'
Snapshot USED=3.2T
example script awk script not working. after removed space
# isi status -q | grep -e "^Size" -e "^Used" -e "^Avail" | awk 'function print (num)
pipe pipe quote> /Size:/ TotalSize=$NF~
pipe pipe quote> /Used:/ TotalUsed=$NF
pipe pipe quote> /Avail:/ TotalAvail=$NF }
pipe pipe quote> END awk 'printf "Snapshot_per :%.1fn", $4'")
pipe pipe quote> Usedw/o=Total Used-Snapshot USED/Total Size
pipe pipe quote> print hostname ": " "t","Total Size:" Total_Size
pipe pipe quote> printf "tttTotalUsed:%.1fn", TotalUsed, "TB"
pipe pipe quote> printf "tttTotalAvail:%.1fn", TotalAvail, "TB"
pipe pipe quote> printf "tttTotalUsed %:%.1fn", used, "TB"
pipe pipe quote> printf "tttSnapshot Used :%.1fn", Snapshot_used, "TB"
pipe pipe quote> printf "tttSnapshot Used %:%.1fn", Snapshot_per, "TB"
pipe pipe quote> printf "tttUsed w/o:%.1fn", Usedw/o, TB)'
awk: syntax error at source line 1
context is
function >>> print <<< (num)
missing
missing )
awk: bailing out at source line 7
Sample Requirement
Total Size : 573 TB
Total Used : 448.0 TB
Total Available : 74 TB
Total Used % : 86.1 % # Total Used(%) = Total Used/Total Size *100 = 86.1(%)
Snapshot Used : 3.2 TB
Snapshot Used % : 0.6 %
Used w/o : 85.5 % # (Total used)-(Snapshot used) / (Total size) = 85.49%
shell-script awk scripting gawk
You cannot have space in variable name, please remove all spaces likeTotalSize
inTotal Size=$NF~
(what is~
here?!) and all others and in printf statements as well.
â Ã±ÃÂsýù÷
Nov 10 '17 at 5:21
@ñÃÂsýù÷Have tried with removing the space still its not working. I have edited the question.
â user3561766
Nov 10 '17 at 9:28
Its not taking the function num.
â user3561766
Nov 10 '17 at 9:49
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to execute 3 command and get the output as a variable which needs some percentage calculation and display the same as the example. can this be executed as script.
First command output
$ isi status -q | grep -e "^Size" -e "^Used" -e "^Avail"
Size:573T
Used:448.0T
Avail:74T
Second command output
$ isi_classic snapshot usage | tail -n 1 | awk 'printf "tttSnapshot USED %=%.1f%%n", $4'
Snapshot USED =0.6%
$ isi_classic snapshot usage | tail -n -1 | awk ' print "tttSnapshot USED:" $1'
Snapshot USED=3.2T
example script awk script not working. after removed space
# isi status -q | grep -e "^Size" -e "^Used" -e "^Avail" | awk 'function print (num)
pipe pipe quote> /Size:/ TotalSize=$NF~
pipe pipe quote> /Used:/ TotalUsed=$NF
pipe pipe quote> /Avail:/ TotalAvail=$NF }
pipe pipe quote> END awk 'printf "Snapshot_per :%.1fn", $4'")
pipe pipe quote> Usedw/o=Total Used-Snapshot USED/Total Size
pipe pipe quote> print hostname ": " "t","Total Size:" Total_Size
pipe pipe quote> printf "tttTotalUsed:%.1fn", TotalUsed, "TB"
pipe pipe quote> printf "tttTotalAvail:%.1fn", TotalAvail, "TB"
pipe pipe quote> printf "tttTotalUsed %:%.1fn", used, "TB"
pipe pipe quote> printf "tttSnapshot Used :%.1fn", Snapshot_used, "TB"
pipe pipe quote> printf "tttSnapshot Used %:%.1fn", Snapshot_per, "TB"
pipe pipe quote> printf "tttUsed w/o:%.1fn", Usedw/o, TB)'
awk: syntax error at source line 1
context is
function >>> print <<< (num)
missing
missing )
awk: bailing out at source line 7
Sample Requirement
Total Size : 573 TB
Total Used : 448.0 TB
Total Available : 74 TB
Total Used % : 86.1 % # Total Used(%) = Total Used/Total Size *100 = 86.1(%)
Snapshot Used : 3.2 TB
Snapshot Used % : 0.6 %
Used w/o : 85.5 % # (Total used)-(Snapshot used) / (Total size) = 85.49%
shell-script awk scripting gawk
I am trying to execute 3 command and get the output as a variable which needs some percentage calculation and display the same as the example. can this be executed as script.
First command output
$ isi status -q | grep -e "^Size" -e "^Used" -e "^Avail"
Size:573T
Used:448.0T
Avail:74T
Second command output
$ isi_classic snapshot usage | tail -n 1 | awk 'printf "tttSnapshot USED %=%.1f%%n", $4'
Snapshot USED =0.6%
$ isi_classic snapshot usage | tail -n -1 | awk ' print "tttSnapshot USED:" $1'
Snapshot USED=3.2T
example script awk script not working. after removed space
# isi status -q | grep -e "^Size" -e "^Used" -e "^Avail" | awk 'function print (num)
pipe pipe quote> /Size:/ TotalSize=$NF~
pipe pipe quote> /Used:/ TotalUsed=$NF
pipe pipe quote> /Avail:/ TotalAvail=$NF }
pipe pipe quote> END awk 'printf "Snapshot_per :%.1fn", $4'")
pipe pipe quote> Usedw/o=Total Used-Snapshot USED/Total Size
pipe pipe quote> print hostname ": " "t","Total Size:" Total_Size
pipe pipe quote> printf "tttTotalUsed:%.1fn", TotalUsed, "TB"
pipe pipe quote> printf "tttTotalAvail:%.1fn", TotalAvail, "TB"
pipe pipe quote> printf "tttTotalUsed %:%.1fn", used, "TB"
pipe pipe quote> printf "tttSnapshot Used :%.1fn", Snapshot_used, "TB"
pipe pipe quote> printf "tttSnapshot Used %:%.1fn", Snapshot_per, "TB"
pipe pipe quote> printf "tttUsed w/o:%.1fn", Usedw/o, TB)'
awk: syntax error at source line 1
context is
function >>> print <<< (num)
missing
missing )
awk: bailing out at source line 7
Sample Requirement
Total Size : 573 TB
Total Used : 448.0 TB
Total Available : 74 TB
Total Used % : 86.1 % # Total Used(%) = Total Used/Total Size *100 = 86.1(%)
Snapshot Used : 3.2 TB
Snapshot Used % : 0.6 %
Used w/o : 85.5 % # (Total used)-(Snapshot used) / (Total size) = 85.49%
shell-script awk scripting gawk
edited Nov 10 '17 at 9:27
asked Nov 10 '17 at 5:14
user3561766
2519
2519
You cannot have space in variable name, please remove all spaces likeTotalSize
inTotal Size=$NF~
(what is~
here?!) and all others and in printf statements as well.
â Ã±ÃÂsýù÷
Nov 10 '17 at 5:21
@ñÃÂsýù÷Have tried with removing the space still its not working. I have edited the question.
â user3561766
Nov 10 '17 at 9:28
Its not taking the function num.
â user3561766
Nov 10 '17 at 9:49
add a comment |Â
You cannot have space in variable name, please remove all spaces likeTotalSize
inTotal Size=$NF~
(what is~
here?!) and all others and in printf statements as well.
â Ã±ÃÂsýù÷
Nov 10 '17 at 5:21
@ñÃÂsýù÷Have tried with removing the space still its not working. I have edited the question.
â user3561766
Nov 10 '17 at 9:28
Its not taking the function num.
â user3561766
Nov 10 '17 at 9:49
You cannot have space in variable name, please remove all spaces like
TotalSize
in Total Size=$NF~
(what is ~
here?!) and all others and in printf statements as well.â Ã±ÃÂsýù÷
Nov 10 '17 at 5:21
You cannot have space in variable name, please remove all spaces like
TotalSize
in Total Size=$NF~
(what is ~
here?!) and all others and in printf statements as well.â Ã±ÃÂsýù÷
Nov 10 '17 at 5:21
@ñÃÂsýù÷Have tried with removing the space still its not working. I have edited the question.
â user3561766
Nov 10 '17 at 9:28
@ñÃÂsýù÷Have tried with removing the space still its not working. I have edited the question.
â user3561766
Nov 10 '17 at 9:28
Its not taking the function num.
â user3561766
Nov 10 '17 at 9:49
Its not taking the function num.
â user3561766
Nov 10 '17 at 9:49
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Original answer:
Totalanswer=$(command1 ; command2)
Subanswer1=$(echo $Totalanswer|grep Sub1)
Subanswer2=$(echo $Totalanswer|grep Sub2)
printf " Answer1:%sn Answer2:%sn" $Subanswer1 $SubAnswer2
Added comment:
The trick is in getting the required information by using the right tools. Using an external (ie. no native shell) command is to be avoided. Replacing the greps with bash native (hint) is left as an exercise for the reader.
It is not really a code snippet sharing site. I think we should share knowledge and not scripts for copy-paste. I suggest to share the knowledge what made you possible to write this script, this is the important and not the script (although having also the script, beside the explanation, is obviously useful).
â peterh
Nov 10 '17 at 6:24
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Original answer:
Totalanswer=$(command1 ; command2)
Subanswer1=$(echo $Totalanswer|grep Sub1)
Subanswer2=$(echo $Totalanswer|grep Sub2)
printf " Answer1:%sn Answer2:%sn" $Subanswer1 $SubAnswer2
Added comment:
The trick is in getting the required information by using the right tools. Using an external (ie. no native shell) command is to be avoided. Replacing the greps with bash native (hint) is left as an exercise for the reader.
It is not really a code snippet sharing site. I think we should share knowledge and not scripts for copy-paste. I suggest to share the knowledge what made you possible to write this script, this is the important and not the script (although having also the script, beside the explanation, is obviously useful).
â peterh
Nov 10 '17 at 6:24
add a comment |Â
up vote
0
down vote
Original answer:
Totalanswer=$(command1 ; command2)
Subanswer1=$(echo $Totalanswer|grep Sub1)
Subanswer2=$(echo $Totalanswer|grep Sub2)
printf " Answer1:%sn Answer2:%sn" $Subanswer1 $SubAnswer2
Added comment:
The trick is in getting the required information by using the right tools. Using an external (ie. no native shell) command is to be avoided. Replacing the greps with bash native (hint) is left as an exercise for the reader.
It is not really a code snippet sharing site. I think we should share knowledge and not scripts for copy-paste. I suggest to share the knowledge what made you possible to write this script, this is the important and not the script (although having also the script, beside the explanation, is obviously useful).
â peterh
Nov 10 '17 at 6:24
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Original answer:
Totalanswer=$(command1 ; command2)
Subanswer1=$(echo $Totalanswer|grep Sub1)
Subanswer2=$(echo $Totalanswer|grep Sub2)
printf " Answer1:%sn Answer2:%sn" $Subanswer1 $SubAnswer2
Added comment:
The trick is in getting the required information by using the right tools. Using an external (ie. no native shell) command is to be avoided. Replacing the greps with bash native (hint) is left as an exercise for the reader.
Original answer:
Totalanswer=$(command1 ; command2)
Subanswer1=$(echo $Totalanswer|grep Sub1)
Subanswer2=$(echo $Totalanswer|grep Sub2)
printf " Answer1:%sn Answer2:%sn" $Subanswer1 $SubAnswer2
Added comment:
The trick is in getting the required information by using the right tools. Using an external (ie. no native shell) command is to be avoided. Replacing the greps with bash native (hint) is left as an exercise for the reader.
edited Nov 10 '17 at 10:23
answered Nov 10 '17 at 6:00
JdeHaan
347213
347213
It is not really a code snippet sharing site. I think we should share knowledge and not scripts for copy-paste. I suggest to share the knowledge what made you possible to write this script, this is the important and not the script (although having also the script, beside the explanation, is obviously useful).
â peterh
Nov 10 '17 at 6:24
add a comment |Â
It is not really a code snippet sharing site. I think we should share knowledge and not scripts for copy-paste. I suggest to share the knowledge what made you possible to write this script, this is the important and not the script (although having also the script, beside the explanation, is obviously useful).
â peterh
Nov 10 '17 at 6:24
It is not really a code snippet sharing site. I think we should share knowledge and not scripts for copy-paste. I suggest to share the knowledge what made you possible to write this script, this is the important and not the script (although having also the script, beside the explanation, is obviously useful).
â peterh
Nov 10 '17 at 6:24
It is not really a code snippet sharing site. I think we should share knowledge and not scripts for copy-paste. I suggest to share the knowledge what made you possible to write this script, this is the important and not the script (although having also the script, beside the explanation, is obviously useful).
â peterh
Nov 10 '17 at 6:24
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403672%2fhow-to-get-multiple-command-output-as-variable-in-awk%23new-answer', 'question_page');
);
Post as a guest
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
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
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
You cannot have space in variable name, please remove all spaces like
TotalSize
inTotal Size=$NF~
(what is~
here?!) and all others and in printf statements as well.â Ã±ÃÂsýù÷
Nov 10 '17 at 5:21
@ñÃÂsýù÷Have tried with removing the space still its not working. I have edited the question.
â user3561766
Nov 10 '17 at 9:28
Its not taking the function num.
â user3561766
Nov 10 '17 at 9:49