Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.