DOS - Parse a property file

Card Puncher Data Processing

About

How to parse a property file in DOS with the F option of the FOR loop.

Snippet

# Comments
myHostName=gerardnico.local
myPort=1521

Dos Script to list the content

:: The lines beginning with # will be skipped
FOR /F "tokens=1,2* delims== eol=# " %%i in ('type "path to\file.properties"') do (
	@echo i = %%i 
	@echo j = %%j
	)
i = myHostName
j = gerardnico.local
i = myPort
j = 1521

Conditional processing with a if statement:

FOR /F "tokens=1,2* delims== eol=# " %%i in ('type "path to\file.properties"') do (
	if "%%i" == "myHostName" @echo    - My Host Name is  %%j 
	if "%%i" == "myPort" @echo    - My Port is  %%j 
	)
- My Host Name is  gerardnico.local
   - My Port is  1521





Discover More
Card Puncher Data Processing
DOS - Parsing (File, Command, Variable) - FOR F option

parsing in DOS is done via the F option of the FOR command where: the option /F means (file|text) processing % and %% indicates that we are in presence of a variable % is used in on-line mode...



Share this page:
Follow us:
Task Runner