Deleting bad lines of data from multiple parameter files.

prmclean.cmd screenshot

When performance testing it is common to find some lines of test data which are no longer valid. They may be user IDs which have expired or simply no longer exist in your test database. Finding and removing these bad lines of test data from parameter files can be time-consuming.

This batch file, prmclean.cmd can be used to remove known bad data from all data files in a data folder.  The batch file does not prompt for folder names and currently relies on the .dat files residing in a folder called LR_TestData.

The batch file can be easily modified to work with any text files.  No additional software is required (e.g. PERL) and this batch file will run on any windows PC.

Batch file Description of action
IF EXIST LR_TestData_old  rd LR_TestData_old /s /q

md LR_TestData_old

 

 

REM Copy all data files to “LR_TestData_old”

for %%d in (h) do (

for /f “delims=” %%a in (‘dir LR_TestData*.dat /b’) do (

copy LR_TestData%%a LR_TestData_old

)

)

 

REM Loop through the .dat files writing contents without bad data into new .tmp files

for %%d in (h) do (

for /f “delims=” %%a in (‘dir LR_TestData*.dat /b’) do (

findstr /V /G:bad.txt LR_TestData%%a > LR_TestData%%a.tmp

)

)

 

 

 

REM Delete old .dat files

del LR_TestData*.dat

 

REM Rename .tmp files into .dat files

ren LR_TestData*.tmp *.

These lines create a folder to keep a copy of the original data files.

 

 

This loop copies all the current data files into a folder called LR_TestData_old.

 

This loop copies data into new data files (with .tmp suffix) without the lines of “known bad” data contained in the file “bad.txt”

 

 

 

Finally the old data files are deleted and the new temporary (.tmp) files are renamed (.dat)


Usage:
Copy the file prmclean.cmd into the folder containing the LR_TestData folder.  Create a text file in this folder called bad.txt containing the “known bad” data.  Run the prmclean.cmd command.

prmclean.cmd screenshot

Sample code:
A sample of this code which can be used to further develop this function is available here.

Author: Richard Bishop

http://about.me/richard_bishop