I have the below block of data.Heap after GC invocations=31 (full 3):   par new generation   total 131008K, used 0K [0x00000000eac00000, 0x00000000f2c00000, 0x00000000f2c00000)    eden space 130944K,   0% used [0x00000000eac00000, 0x00000000eac00000,   0x00000000f2be0000)  from space 64K,   0% used [0x00000000f2be0000, 0x00000000f2be0000, 0x00000000f2bf0000)    to   space 64K,   0% used [0x00000000f2bf0000, 0x00000000f2bf0000, 0x00000000f2c00000)   concurrent mark-sweep generation total 131072K, used 48549K [0x00000000f2c00000, 0x00000000fac00000, 0x00000000fac00000)   concurrent-mark-sweep perm gen total 30000K, used 19518K [0x00000000fac00000, 0x00000000fc94c000, 0x0000000100000000)  }I need to extract the below data of total and used numeric data without K for the below. i.e. value1=131008, value2=0,value3=131072,value4=48549,value5=30000 and value6=19518should be extracted from the below:par new generation   ***total*** 131008K, ***used*** 0Kconcurrent mark-sweep generation ***total*** 131072K, used 48549K concurrent-mark-sweep perm gen ***total*** 30000K, ***used*** 19518KI know how to extract the data for fixed length values like below.value1=`grep par new generation | cut -c27-31However, the above block of data has variable length values. Not sure how extract these. Can you please help.
Extract values from block of data
sed;awk;grep
If your goal is to extract those six numbers into shell variables, it is probably more convenient to put them in a bash array like this:$ data=($(awk '/^ *(par|concurrent)/{printf %s %s ,$5+0,$7+0}' file))You can verify that the array has the correct values using declare:$ declare -p datadeclare -a data='([0]=131008 [1]=0 [2]=131072 [3]=48549 [4]=30000 [5]=19518)'If, instead, you just want to print the values:$ awk '/^ *(par|concurrent)/{printf value%s=%s\nvalue%s=%s\n,++c,$5+0,++c,$7+0}' filevalue1=131008value2=0value3=131072value4=48549value5=30000value6=19518How is works/^ *(par|concurrent)/This matches only on the lines that start with par or concurrent.printf %s %s ,$5+0,$7+0For the matched lines, we print out the fifth and seventh fields.  By adding zero to these values, we force awk to convert them to numbers.  This has the side-effect of removing the k.