I'm tackling a rather LARGE flat file (213kb) which overtime needs to be converted to a database... I'm trying to get together a parser to take care most of the tedium that is to follow but it's kind of beyond the usual small regex stuff I've dealt with...
Here's an example dataset:
192.168.1.2 / 255.255.255.0 [252 ips] server.example.com id001 Random text about assigned machine
[switch-id-1 port 01]
.1 = gateway
.2 - 254 = id001 server.example.com.
.255 = bcast
that is the basic outline of a few hundred blocks of assignment which has some variety in the spacing (lines 4,5,6 have lead in spacing that the forum removes) but that's the general format...
Now, I can write little regex's for each part BUT since this file and it's data aren't uniform I can't simply rely on the blocks just repeating... there's other notes, comments, partial blocks, etc which will have to be manually converted
So, what I basically need to pull from this 'pattern' is the following:
line 1) IP address, mask, hostname and id (these can be "switched" in some) and the random text
line 2) switch id number and port number
now, again, writing the little regexs to pull these out is easy, but detecting the block/pattern to know that I need to run these little regexs is what I'm struggling with
At first I thought I'd need to write a regex to detect the entire block but I doubt that's the ideal way and might be able to get away with just the first two lines...
Either way it's left me scratching my head... Any ideas?
MOD EDIT: Added 'CODE' bbcode tags to perserve spacing. 😉