I need to count the number of occurrences of a pattern, say 'key', between each occurrence of a different pattern, say 'lu'.
Here's a portion of the text I'm trying to parse:
lu S1234L_149_m1_vg.6, part-att 1, vdp-att 1 p-reserver IID 0xdb
registrations:
key 4156 4353 0000 0000
initiator (217) fcp portName=0x10000000c9862398
target (6) fcp portName=0x2007000123000591 nodeName=0x2000000123000591
key 4156 4353 0000 0000
initiator (217) fcp portName=0x10000000c9862398
target (18936) fcp portName=0x20070001230004e1 nodeName=0x20000001230004e1
key 4156 4353 0000 0000
initiator (217) fcp portName=0x10000000c9862398
target (0) fcp portName=0x20070001230004f5 nodeName=0x20000001230004f5
key 4156 4353 0000 0000
initiator (217) fcp portName=0x10000000c9862398
target (34960) fcp portName=0x20070001230004c1 nodeName=0x20000001230004c1
key 4156 4353 0000 0000
initiator (219) fcp portName=0x10000000c9862399
target (54648) fcp portName=0x20080001230004e1 nodeName=0x20000001230004e1
key 4156 4353 0000 0000
initiator (219) fcp portName=0x10000000c9862399
target (6) fcp portName=0x20080001230004f5 nodeName=0x20000001230004f5
key 4156 4353 0000 0000
initiator (219) fcp portName=0x10000000c9862399
target (7) fcp portName=0x2008000123000591 nodeName=0x2000000123000591
key 4156 4353 0000 0000
initiator (219) fcp portName=0x10000000c9862399
target (7) fcp portName=0x20080001230004c1 nodeName=0x20000001230004c1
lu S5678L_1FF_m1_vg.2, part-att 1, vdp-att 1 p-reserver IID 0xdb
registrations:
key 4156 4353 0000 0000
initiator (219) fcp portName=0x10000000c9862399
target (12336) fcp portName=0x20080001230004f5 nodeName=0x20000001230004f5
key 4156 4353 0000 0000
initiator (219) fcp portName=0x10000000c9862399
target (7) fcp portName=0x20080001230004c1 nodeName=0x20000001230004c1
key 4156 4353 0000 0000
initiator (219) fcp portName=0x10000000c9862399
target (7) fcp portName=0x20080001230004e1 nodeName=0x20000001230004e1
key 4156 4353 0000 0000
initiator (219) fcp portName=0x10000000c9862399
target (7) fcp portName=0x2008000123000591 nodeName=0x2000000123000591
Here's the output I'm hoping to achieve:
$ someawkcommand myexample.txt
lu S1234L_149_m1_vg.6: 8
lu S5678L_1FF_m1_vg.2: 4
With my rudimentary awk skills I thought I might build on answers to similar questions in the forum by creating separate temporary files for each occurrence of 'lu' and counting the occurrences of 'key' with grep. I think I'm fighting Darwin's implementation of awk though, e.g.:
awk '/lu/{close("file"f);f++}{print $0 > "file"f}' myexample.txt
awk: syntax error at source line 1
context is
/lu/{close("file"f);f++}{print $0 > >>> "file"f <<< }
awk: illegal statement at source line 1
I'm also not sure if this something better suited for building with sed, e.g. something including:
sed '/lu/,/lu/ p' myexample.txt
Thanks for any help or examples you can point me to..