Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda