1

we are trying to convert the value in GB to TB, is there anything missing in my code.

Sample output

isi status -q | grep -e "^Size" -e "^Used" -e "^Avail"
Size:       501T (5041T Raw)    19T (19T Raw)
Used:       440G (80%)          1.4T(7%)
Avail:      61T (12%)           18T (93%)

Require Output In Some cases Used value can be in GB need to convert it into TB

Size:       501T 
Used:       0.39T
Avail:      61T 

I tried this but not getting the expected result

isi status -q | grep -e "^Size" -e "^Used" -e "^Avail" | awk '{print $1 $2}' | awk 'function num2gb(n) { if (n ~ /T$/) return n / 1; return n / 14; }
/Size:/ { size=$NF }
/Used:/ { used=num2gb($NF) }
END {
print size
print "used=" used }'
2

I don't understand your arithmetic, but perhaps something like

awk '/^(Size|Used|Avail):/ {
  $2 = $2 ~ /G$/ ? sprintf("%.2fT", ($2+0)/1024) : $2;
  print $1, $2;
}' OFS='\t' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.