Solved Batch Script for Source File Validation

July 16, 2012 at 10:58:52
Specs: Windows 7
Hi All,

My Input file is coming with .dat extension,i need to open the file and check whether the fields are comma separted and also need to check if there are any negative values for any fields.

Is this can be done in batch scripting? Please anyone help me with this.


See More: Batch Script for Source File Validation

Report •

July 16, 2012 at 17:58:28
can you post a sample of the incoming, (including the "header" or col.heads line, if any)?
by numeric, can I assume "not scientific notation"? Need to test for all bytes of field somewhere in string "-.0123456789" which covers the real numbers i believe.

Batch can test for comma in string, but without a file-structure description, that is of no use (ie: no. of fields, at least).

vbscript has better equipment for this, but batch can do it also, up to a point...

Report •

July 17, 2012 at 07:36:59
Thanks for the reply,

My sample file looks like:


there is no header and footer available.

Report •

July 17, 2012 at 20:16:21
✔ Best Answer
I still don't know how to determine if comma-sep, other than a fixed count of commas, so here's a tentative attempt to count both commas and dashes:

@echo off & setlocal enabledelayedexpansion

for /f "tokens=*" %%a in (xx.dat) do (
echo %%a
call :kount "%%a" "," "-"
echo commas counted: !b!
echo negatives counted: !c!
goto :eof
goto :eof

set xx=%~1
set bb=%~2
set cc=%~3
set test=%xx%
set test=%xx:~0,1%
set xx=%xx:~1%
:echo xx is now:[%xx%]
if "%test%" equ "%bb%" set /a b+=1
if "%test%" equ "%cc%" set /a c+=1
if defined xx goto :kount1

You'll notice this only reads the first line of the file. Maybe you can start with this and get what you need...

Report •

Related Solutions

Ask Question