Solved Batch File to Read Number and Add text to it

July 22, 2011 at 09:01:56
Specs: Windows 7
I was looking for a batch file to make what I'm doing a little easier. I have 3670 item numbers that I need to output to a file so I can import this file into our software.The file I need looks like this....

<DeleteItems>
<DeleteItemStart>22560</DeleteItemStart>
<DeleteItemEnd>22560</DeleteItemEnd>
</DeleteItems>

These four lines have to be typed for each item number. Is there a way to write a batch file that will read the item numbers from numbers.txt and write these lines to the file?


See More: Batch File to Read Number and Add text to it

Report •


#1
July 22, 2011 at 19:02:55
✔ Best Answer
Untested.

Good luck.

@echo off>output.txt       &:: MyRef 592 
cls
setlocal enabledelayedexpansion

set line1="<DeleteItems>"
set line2="<DeleteItemStart>^!nbr^!</DeleteItemStart>"
set line3="<DeleteItemEnd>^!nbr^!</DeleteItemEnd>"
set line4="</DeleteItems>"

for /f %%A in (numbers.txt) do (
    set nbr=%%A
        for /f %%1 in ("!line1!") do echo %%~1>>output.txt
        for /f %%1 in ("!line2!") do echo %%~1>>output.txt
        for /f %%1 in ("!line3!") do echo %%~1>>output.txt
        for /f %%1 in ("!line4!") do echo %%~1>>output.txt
)


Please come back & tell us if your problem is resolved.


Report •

#2
July 27, 2011 at 05:28:27
You rock Wahine!! This worked......thank you so much!!!!!

Report •

#3
July 27, 2011 at 14:50:59
You're welcome - Thanks for coming back to report your success.


Please come back & tell us if your problem is resolved.


Report •
Related Solutions


Ask Question