how to get multiple command output as variable in awk

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











up vote
0
down vote

favorite
1












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%






share|improve this question






















  • 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










  • Its not taking the function num.
    – user3561766
    Nov 10 '17 at 9:49














up vote
0
down vote

favorite
1












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%






share|improve this question






















  • 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










  • Its not taking the function num.
    – user3561766
    Nov 10 '17 at 9:49












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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%






share|improve this question














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%








share|improve this question













share|improve this question




share|improve this question








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 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










  • 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











  • @αғ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










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.






share|improve this answer






















  • 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










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f403672%2fhow-to-get-multiple-command-output-as-variable-in-awk%23new-answer', 'question_page');

);

Post as a guest






























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.






share|improve this answer






















  • 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














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.






share|improve this answer






















  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































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?