Reputation: 204
I execute the command free -mo
in linux and my output is:
total used free shared buffers cached
Mem: 64401 33265 31135 0 667 15455
Swap: 4099 0 4099
But i need the output:
total used free
Mem: 64401 33265 31135
Swap: 4099 0 4099
I intended to use free -mo | awk '{print $1,$2,$3,$4}'
but my result is:
total used free shared
Mem: 64401 33268 31132
Swap: 4099 0 4099
I appreciate your help .
Upvotes: 2
Views: 2897
Reputation: 784998
You can use:
free -mo |
awk '{print (NR==1?"Type":""), $1, $2, $3, (NR==1?"":$4)}' |
column -t
Added a column
Type` for make first row a consists of 4 column column -t
is for tabular formattingOutput:
Type total used free
Mem: 2003 163 1840
Swap: 1430 0 1430
Upvotes: 3
Reputation: 15204
Preserving right aligned numbers:
free -mo | awk 'BEGIN{len=0} NR==1{len=length(gensub(/free.*$/, "free",1))} {print substr($0,1,len)}'
total used free
Mem: 7913 7377 535
Swap: 8115 569 7546
Upvotes: 1
Reputation: 67467
another awk
without filler header
$ awk -v OFS='\t' 'NR==1{print "",$1,$2,$3;next} {print $1,$2,$3,$4}' file
total used free
Mem: 64401 33265 31135
Swap: 4099 0 4099
Upvotes: 1