I'm trying to use AWK to post the second row of last line of this command (the total disk space):
df --total The command I'm using is:
df --total | awk 'FNR == NF {print $2}' But it does not get it right. Is there another way to do it?
You're using the awk variable NF which is Number of Fields. You might have meant NR, Number of Rows, but it's easier to just use END:
df --total | awk 'END {print $2}' You can use tail first then use awk:
df --total | tail -1 | awk '{print $2}' One way to do it is with a tail/awk combination, the former to get just the last line, the latter print the second column:
df --total | tail -1l | awk '{print $2}' A pure-awk solution is to simply store the second column of every line and print it out at the end:
df --total | awk '{store = $2} END {print store}' Or, since the final columns are maintained in the END block from the last line, simply:
df --total | awk 'END {print $2}' $2 an a variable, just print it in an end section.
--outputto indicate the exact fields you want to print. For example,df --output=size | tail -1. More info in How to select a particular column in linux df command