Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Replace First two lines of file with (removing schema)

Newfie_LoverNewfie_Lover Posts: 2Member
I am having a bear of a time getting a batch file to delete the first two lines of every file and replace them with a file of the same name and

Comments

  • skorpio07skorpio07 Posts: 3Member
    make a batch file called changelines.cmd
    @echo off
    echo.
    for /f "tokens=1* delims= " %%a in (%1) do (
    if %%a==^<?xml echo. 2>%temp%
    ewfile.tmp
    if %%a==^ >>%temp%
    ewfile.tmp
    if not %%a==^<?xml if not %%a==^<scenarioFile echo %%a%%b >>%temp%
    ewfile.tmp
    )
    copy /y %temp%
    ewfile.tmp %1 > nul
    del %temp%
    ewfile.tmp

    now you can run this from the command prompt:
    for %a in (*.ext) do changelines %a

    replace *.ext with the wildcard of your excel files


  • skorpio07skorpio07 Posts: 3Member
    make a batch file called changelines.cmd
    @echo off
    echo.
    for /f "tokens=1* delims= " %%a in (%1) do (
    if %%a==^<?xml echo. 2>%temp%
    ewfile.tmp
    if %%a==^ >>%temp%
    ewfile.tmp
    if not %%a==^<?xml if not %%a==^<scenarioFile echo %%a%%b >>%temp%
    ewfile.tmp
    )
    copy /y %temp%
    ewfile.tmp %1
    del %temp%
    ewfile.tmp

    now from the command line, do this:
    for %a in (*.ext) do changelines %a

    replace *.ext with the filename and type of your excel files.
  • skorpio07skorpio07 Posts: 3Member
    make a batch file called changelines.cmd
    @echo off
    echo.
    for /f "tokens=1* delims= " %%a in (%1) do (
    if %%a==^<?xml echo. 2>%temp%
    ewfile.tmp
    if %%a==^ >>%temp%
    ewfile.tmp
    if not %%a==^<?xml if not %%a==^<scenarioFile echo %%a%%b >>%temp%
    ewfile.tmp
    )
    copy /y %temp%
    ewfile.tmp %1
    del %temp%
    ewfile.tmp

    now from the command line, do this:
    for %a in (*.ext) do changelines %a

    replace *.ext with the filename and type of your excel files.
Sign In or Register to comment.