I have what appears to me a complex text file that include around 300 entries. I have no idea how to go about parsing this file to get the output I want. Each of my network users has an entry in the file. So in the text file, each user name starts with:
USER:martha
USER:Othello
USER:darwin
Underneath each user entry in the file there are a host of information I require , but one user can have one entry and another can have multiple entries. Here is the example of 3 such entries
USER:martha
POSITION: 170.198.82.13 [VLT(304394),PT(FULL)]
CLIENT: jcrm19.1.p2ps -258-
ACCESSPOINT: 170.198.82.13/net
APPLICATION: 91
USER:othello
POSITION: 170.198.80.212 [VLT(307571),PT(FULL)]
CLIENT: jcrm15.1.p2ps -258-
ACCESSPOINT: 170.198.80.212/net
APPLICATION: 256
CLIENT: jcrm15.1.p2ps -258-
ACCESSPOINT: 170.198.80.212/net
APPLICATION: 256
POSITION: 170.198.80.209 [VLT(306561),PT(FULL)]
CLIENT: jcrm14.1.p2ps -258-
ACCESSPOINT: 170.198.80.209/net
APPLICATION: 256
CLIENT: pwrm14.1.p2ps -258-
ACCESSPOINT: 170.198.80.209/net
APPLICATION: 256
CLIENT: pwrm14.1.p2ps -258-
ACCESSPOINT: 170.198.80.209/net
APPLICATION: 256
USER:darwin
POSITION: 170.198.19.102 [VLT(297987),PT(FULL)]
CLIENT: jcrm16.1.p2ps -258-
ACCESSPOINT: 170.198.19.102/net
APPLICATION: 91
The final output should look as follow:
USER Position Client Application
Martha 170.198.82.13 jcrm19 91
Othello 170.198.80.212 jcrm15 256
Othello 170.198.80.209 jcrm14 256
Martin 170.198.19.102 jcrm16 91
I have some experience with arrays and I could grep out some of the information and assign to variable and print them. But I just don't know how to read the information into the arrays as the entries under each "USER" since they are of different length and content.
So How do I read USER: martha and then jump to user:othello ? Also, under user:othello there are two "Positions" that I need to grab. I just don't know how to put the content I'm looking for into array variables or regular variables. I never had to parse a file that had different length and content data for each use. Not sure how many lines I have to read before I start reading and assigning values to array or values for the next user> Can you provide some hints or perhaps a piece of code that I can start with ?
Thanks