I have a need to do the following:
Read the first line of a text file, grab that value, and then spool to another file as the value of the variable (shown below), based off conditions specified in the batch file and then go to 2nd line of text file and so on and so forth. The amount of lines in the text file will vary each week, so I'd rather not hard code.
Here is my process and its working fine for the first line of the file. Now I need help looping back up and performing the same process for each line of the text file.
NOTE: Each line of the text file is only 1 value/string. For instance, it looks like this:
Value1
Value2
Value3
Value4
The below code works, but only gets the first line of the text file and outputs. I need to loop back through the remaining lines of the text file.
Code: Select all
@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (00_TableNames.txt) do (
if !myvar!'==' set myvar=%%a
)
echo myvar is set to !myvar!
echo --table creation > "00_%myvar%.sql"
echo SET WRAP OFF; >> "00_%myvar%.sql"
echo SET NEWPAGE NONE; >> "00_%myvar%.sql"
echo SET PAGESIZE 0; >> "00_%myvar%.sql"
echo SET SPACE 0; >> "00_%myvar%.sql"
echo SET LINESIZE 16000; >> "00_%myvar%.sql"
echo SET ECHO OFF; >> "00_%myvar%.sql"
echo SET FEEDBACK OFF; >> "00_%myvar%.sql"
echo SET VERIFY OFF; >> "00_%myvar%.sql"
echo SET HEADING OFF;" >> "00_%myvar%.sql"
echo SET TERMOUT OFF; >> "00_%myvar%.sql"
echo SET TRIMOUT ON; >> "00_%myvar%.sql"
echo SET TRIMSPOOL ON; >> "00_%myvar%.sql"
echo SET COLSEP ','; >> "00_%myvar%.sql"
echo spool 00_%myvar%.txt >> "00_%myvar%.sql"
echo select * from %myvar%; >> "00_%myvar%.sql"
Tablename should be replaced by each value of the text file. Therefore, if there are 24 values (lines), there should be 24 separate files with the following values in them:
--table creation
SET WRAP OFF;
SET NEWPAGE NONE;
SET PAGESIZE 0;
SET SPACE 0;
SET LINESIZE 16000;
SET ECHO OFF;
SET FEEDBACK OFF;
SET VERIFY OFF;
SET TERMOUT OFF;
SET TRIMOUT ON;
SET TRIMSPOOL ON;
SET COLSEP ',';
spool 00_VALUE1.txt
select * from VALUE1;
Thank you!