0

I have a log file like the sample below:

Pool id 1000c2
signal sizes 8
sig_conf       63     127     255     511    1663    4095    9247   65535
sig_alloc     214       8      38       1       4       0       0       0
stack sizes 8
stk_conf      256     512    1024    2048    4096    8192   16384   65536
stk_alloc       0       0       0       8       6      10       6       0
fragment info
fragment  baseaddr  lastaddr      size   sigsize   stksize   unused  watermark_used%
0         018ae000  01d72b40   5000000    651680    245760   4102560      17

Current Pool Usage Info
Total_Pool_Size  Current_Used_Pool  Current_Used_Pool%
5000000         252535                     5
blocks
30111a    2010f0    29010d0   6000c0    
$ 

I need the value under the heading "Current_Used_Pool%". There are a number of such logs and the values are varying but the heading remains constant.

I tried to use awk but have failed so far. Please help.

slyclam
  • 290
  • 1
  • 9
  • 23

3 Answers3

1

Another approach:

awk '/Current_Used_Pool%/{N=NR+1;next} NR==N{print $3}'
jijinp
  • 2,592
  • 1
  • 13
  • 15
  • Though it'll probably be fine in this case given the OPs sample data, that actually implements something slightly different than the OP asked for - that implements `printing the line after the last consecutive occurrence of the condition`, not just `printing the line after the condition`. – Ed Morton Mar 02 '16 at 13:52
1

The common, idiomatic awk approach is to just set/test a flag:

awk 'f{print $3;f=0} /Current_Used_Pool%/{f=1}'

See https://stackoverflow.com/a/18409469/1745001 for more examples of how to print records relative to some other record.

@slyclam I see under a different answer you wrote got syntax error awk: syntax error near line 1 awk: illegal statement near line 1 - that error message means you are using old, broken awk (/bin/awk on Solaris). Never use that awk is it is, well, old and broken. On Solaris use /usr/xpg4/bin/awk or, slightly inferior, nawk.

Community
  • 1
  • 1
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
0

You can use this awk command to search for the value under a fixed column heading:

awk -v col="Current_Used_Pool%" '$0 ~ col {
   for(i=1; i<=NF; i++)
      if ($i == col) {
         c=i
         n=NR+1
         break
      }
} NR==n {
   print $c
   exit
}' file

Output:

5
anubhava
  • 761,203
  • 64
  • 569
  • 643