1.

Solve : Parsing text file to get variables.?

Answer»

I'm trying to parse multiple text files to determine whether a dummy mac was used or not for a setup script. MAC is the 3rd field. I thought about looking for the first X# of characters but given that I don't know if the reserved IP is 1, 2, or 3 digits long, I need to figure out how to get it for all 3 conditions. (batch file will be run on W2k)

The files would all look similar to this example:
RIP,7,000000000007,TM####A,"Unassigned",DHCP
RIP,80,000000000080,WS####A,"Unassigned",DHCP
RIP,81,000000000081,WS####B,"Unassigned",DHCP
RIP,203,000000000203,WS####RR,"Unassigned",DHCP
RIP,204,000000000204,WS####SS,"Unassigned",DHCP
RIP,205,000000000205,WS####TT,"Unassigned",DHCP
RIP,219,001E4F4DBC54,WS####ZZ,"DELL_GX745",DHCP

My thought is once I figure out how to get the MAC inta a variable, that I will run multiple loops that get the MAC from the control file, and compare it to what is in the configured file dump. With one loop to do this for each file that I need to compare.

Worst case, I will just do multipe search and replaces for RIP,#, and replace it out so that I know the first 12 will ALWAYS be the MAC.

Thank you in advance for your HELP!Code: [SELECT]@echo off
setlocal enabledelayedexpansion

REM line format in test.txt is as follows:
REM RIP,204,000000000204,WS####SS,"Unassigned",DHCP

REM The FOR line does this:
REM for each line in test.txt, deem the line
REM to be 6 tokens SEPARATED by commas.
REM create one explicit variable called %%A
REM and load the first token into it.
REM
REM Load the remaining five tokens into
REM five implicit variables called %%B %%C %%D %%E %%F
REM ready to be expanded if called for.

for /f "tokens=1-6 delims=," %%A in (test.txt) do (

REM get the 3rd token by expanding %%C
REM and store it in the variable called mac.
set mac=%%C

REM In a loop, we need to USE delayed expansion
echo !mac!
)
That's exactly what I was looking to get. I will be plugging away at getting to the next steps from these results. Thanks much.



Discussion

No Comment Found