MS-DOS

Moderators: blip
Number of threads: 389
Number of posts: 904

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Replace First two lines of file with <scenarioFile> (removing schema) Posted by Newfie_Lover on 16 Apr 2012 at 4:44 AM
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 “<scenarioFile>”

So changing

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<scenarioFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<updateRec>
<ec>CME</ec>

To

<scenarioFile>
<updateRec>
<ec>CME</ec>



Since it is a batch file, you can show me how to do this to one file, and then I can copy paste the rest into the batch (I hope that makes sense)

The unwanted schema was added by Excel.

Thank you for your help.
Report
Replace First two lines of file with <scenarioFile> (removing schema) Posted by skorpio07 on 13 May 2012 at 3:44 PM
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%\newfile.tmp
if %%a==^<scenarioFile echo ^<scenarioFile^> >>%temp%\newfile.tmp
if not %%a==^<?xml if not %%a==^<scenarioFile echo %%a%%b >>%temp%\newfile.tmp
)
copy /y %temp%\newfile.tmp %1 > nul
del %temp%\newfile.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


Report
Replace First two lines of file with <scenarioFile> (removing schema) Posted by skorpio07 on 13 May 2012 at 3:51 PM
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%\newfile.tmp
if %%a==^<scenarioFile echo ^<scenarioFile^> >>%temp%\newfile.tmp
if not %%a==^<?xml if not %%a==^<scenarioFile echo %%a%%b >>%temp%\newfile.tmp
)
copy /y %temp%\newfile.tmp %1
del %temp%\newfile.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.
Report
Replace First two lines of file with <scenarioFile> (removing schema) Posted by skorpio07 on 13 May 2012 at 3:54 PM
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%\newfile.tmp
if %%a==^<scenarioFile echo ^<scenarioFile^> >>%temp%\newfile.tmp
if not %%a==^<?xml if not %%a==^<scenarioFile echo %%a%%b >>%temp%\newfile.tmp
)
copy /y %temp%\newfile.tmp %1
del %temp%\newfile.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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.