DOS script to read one file into another -
i discovered couldnt granted bulkadmin or sysadmin role on hosted sql server db , trying bypass bulk insert operation creating .sql file containing insert statements. insert statements created using xls macro, theres bit of manual bodyshopping work doing now. let me draw problem here.
i have text file following contents -
10/05/2011 01:21 pm 1-16332-1008261.psa 10/05/2011 01:21 pm 1-16332-1011698.psa 10/05/2011 01:21 pm 1-16332-1023151.psa 10/05/2011 01:21 pm 1-16332-1035695.psa 10/07/2011 03:36 pm 1-16332-1023193.psa 10/07/2011 03:36 pm 1-16332-1035694.psa 6 file(s) 8,933,754 2 dir(s) 1,675,268,096 free
what want achieve in final output file -
insert xyz.abcd values('10/05/2011', '1-16332-1008261.psa'); insert xyz.abcd values('10/05/2011', '1-16332-1011698.psa'); insert xyz.abcd values('10/05/2011', '1-16332-1023151.psa'); insert xyz.abcd values('10/05/2011', '1-16332-1035695.psa'); insert xyz.abcd values('10/07/2011', '1-16332-1023193.psa'); insert xyz.abcd values('10/07/2011', '1-16332-1035694.psa'); go
please take note last 2 lines input text file dinged in final output sql file. kind of automating xls macro manually doing dos scripting 'insert xyz.abcd values' considered constant string written each new line before actual date , filename file been read. name final output file .sql , execute remotely computer. can please me if can doable in dos programming or not.
i have tried present similar problem in post trying delete, unable so. guess didnt explain other 1 properly.
i know can redirect string literal file echo command challenge how read fraction of line 1 file , put them new file.
thanks!
please put following code notepad , save cmd batch file (e.g. convert2sqlfile.cmd). run command line 3 parameters, while:
- 1st parameter contains path source file data read
- 2nd parameter contains path destination file data saved
- 3rd parameter contains table name should stored in sql command instead of "xyz.abcd" have in request
hope helps.
regards,
standa
@echo off setlocal set app.sourcefile=%1 set app.destinationfile=%2 set app.table=%3 /f "usebackq tokens=1,4" %%i in (`type %%app.sourcefile%%`) ( if #%%j# neq ## ( if #%%j# neq #free# ( echo insert %app.table% values ^('%%i', '%%j'^); >> %app.destinationfile% ) ) ) echo go >> %app.destinationfile%
Comments
Post a Comment