0

I am not so good with Linux commands & Can someone please tell me what would be an efficient way to gather total(33521664K) & used(22917322K) values from this command result

> jcmd 27047 GC.heap_info 
27047:
 garbage-first heap   total 33521664K, used 22917322K [0x00007XXX, 0x00007XXX, 0x00007XX)
  region size 8192K, 1307 young (10706944K), 9 survivors (73728K)
 Metaspace       used 154942K, capacity 169384K, committed 210432K, reserved 210944K

I have thought of using grep with "garbage-first" which will give me the line of information I want & doing awk. Most likely there could a better way of grabing those values.

rvk_user
  • 1
  • 2

1 Answers1

0

If your format is always "total" followed by digits and "K", then grep will do:

grep -o 'total [0-9]\+K' | grep -o '[0-9]*'
grep -o 'used [0-9]\+K' | grep -o '[0-9]*'

The first grep matches total/used followed by the kilobytes and outputs only the match. The second grep extracts the number from the first match

knittl
  • 246,190
  • 53
  • 318
  • 364