Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
How Extract columns to free command

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 .

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can use:

free -mo |
awk '{print (NR==1?"Type":""), $1, $2, $3, (NR==1?"":$4)}' |
column -t
  • Added a columnType` for make first row a consists of 4 column
  • column -t is for tabular formatting

Output:

Type   total  used  free
Mem:   2003   163   1840
Swap:  1430   0     1430
over 4 years ago · Santiago Trujillo Report

0

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
over 4 years ago · Santiago Trujillo Report

0

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
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!