Is it possible to use REGEX find/replace to copy search term to the begining of multiple lines until a new match is found

I am responsible for performing SAN zoning for my environment. I receive data in an Excel format that then needs to be pruned and formatted to be used as a script on the switches.

  1. Data may contain hundreds or thousands of lines total. Each “section” starts with a “zonename” in the format AAnnFCPAAAAA where nn is a pair of HEX characters [0-9a-f]{2}, and FCP is static
  2. This is followed by dozens of lines, where I prune the first 3 fields to be left with a 16 digit HEX number [0-9a-f]{16}

I pull in multiples of data sets that look like this:

AAnnFCPAAAAA
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef
lpar xx 1234 0123456789abcdef

I use the following REGEX to prune what I don’t want:

Find: \t*$

Replace: <leave blank>

Find: ^(\w{2,}).*\t

Replace: <leave blank>
Find:([0-9a-f]{16})\r\n([0-9a-f]{16})\r\n([0-9a-f]{16})\r\n([0-9a-f]{16})\r\n([0-9a-f]{16})\r\n([0-9a-f]{16})\r\n([0-9a-f]{16})\r\n([0-9a-f]{16})\r\n

Replace:\1;\2;\3;\4;\5;\6;\7;\8″\r\n

Find:([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})

Replace:\1:\2:\3:\4:\5:\6:\7:\8

This leaves me with a data set that looks something like this:

AAnnFCPAAAAA
01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF”

01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF;01:23:45:67:89:AB:CD:EF”

The number of lines following the zone name AAnnFCPAAAAA is variable, typically betwen 8 and 30 after running the prior find/replace sequences.
While I can (and do) use the block copy/replace function of NP++ currently, when I have hundreds of these groupings I would like to search (capture) the zone name, and insert it in front of every line of WWPNs, but ONLY until I match a new zone name, then repeat through the end of the file.

The search I use to capture the zone name is as follows:

^(\w{2}[0-9a-f]{2}fcp.*)$
I can reuse that search to clean up lines that have only the zonename as the end of a recorded macro.

Read more here: Source link