0

I Need to output a file like this:

Number  App_Date    Reference   Approval
01/00   24/10/2013  REFERENCE01 12345

The top line is constant but I need to change the second line to variables out of a list, (at the moment they are in a .csv file but txt would also be possible) then save as the document reference.

i.e. the above file would be REFERENCE01.txt

and the next file would be for example: REFERENCE03.txt

Number  App_Date    Reference   Approval
03/04   24/10/2013  REFERENCE03 54321

At the moment the .csv file is similar to:

Number  App_Date    Reference   Approval
01/00   24/10/2013  REFERENCE01 12345
03/04   24/10/2013  REFERENCE03 54321
13/00   24/10/2013  REFERENCE13 67890

Any assistance anyone could give would be greatly appreciated

  • Welcome to StackOverflow! Could you please include in your question what you have already tried? – Andrew Oct 24 '13 at 22:42

2 Answers2

0
for /f  "skip=1 tokens=*" %%i in (file) do (for /f "usebackq tokens=1-4" %%a in ('%%i') do (echo Number  App_Date    Reference   Approval>"%%c.txt"&echo %%i>>"%%c.txt"))

try that. . . ;)

cure
  • 2,588
  • 1
  • 17
  • 25
  • Actually very close. The only thing I see wrong is your output files are missing the .txt extension – dbenham Oct 25 '13 at 15:07
0

Try this batch file. Adapt as needed

@echo off

    setlocal enableextensions enabledelayedexpansion

    set input=data.csv

    for /F "tokens=*" %%h in ('type "%input%" ^| find "App_Date"') do (
        set header=%%h
    )

    for /F "tokens=*" %%l in ('type "%input%" ^| findstr /r "REFERENCE[0-9]" ') do (
        for /F "tokens=3" %%r in ('echo %%l') do (
            echo %header% 
            echo %%l      
        ) > %%r.txt
    )

    endlocal
MC ND
  • 69,615
  • 8
  • 84
  • 126