0

I am currently facing a challenging script where I need to grep for the following 700e10 for example under the column partnum and find/grep for "rstcb" above that line. The problem is that it is not a fixed number of lines above the grep for "rstcb".

rstcb 700000036d048e8 tid 19150545
isfd  op_mode    op_flags   partnum   ucnt ocnt lk ra   partp          ocnt ucnt
0     400        297        700da0    2    2       1    700000023b8c028 715  715
1     2          3          700da0    2    2       0    700000023b8c028 715  715
2     1000400    403        700e10    1    0       0    70000002c768738 0    604
3     1000400    403        700e11    1    0       0    70000002c89a028 0    302
4     1000400    3          70051e    1    1       0    7000000242a1028 318  698
5     1000440    3          70051f    1    1       0    7000000242a15c8 318  396

Steps to get this

Step 1: Select hex(partnum) from systables where tabname = "stocks"

Output for example: 0x00700e10

Step 2: (informix) Run onstat -g opn | grep -i 700e10

Step 3: You will get the the above text from image for example

I would like to include a grep that can search for the text rstcb above the initial result from step 2. Once I have that I would like to awk '{print $2}' the number 700000036d048e8

0

1 Answer 1

1

If I got the requirement right, a brief awk should do it:

$ cat > test
rstcb 999999999999
rstcb 700000000123
foo bar doo partnum
1 2 3 4
5 6 7 7001e0

$ awk -vkey=7001e0  '/^rstcb/ {val=$2; next} $4 == key {print val; exit}' test   
700000000123

This saves the second field of any line starting with rstcb, and prints the saved value (the last one) if a line is met where the fourth field matches 7001e0 or whatever key was set to on the command line.

The next in the first code block skips the second test, and the exit is there to stop after the first match. If you remove that, you get multiple hits, but they might be from the same rstcb line.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .