|
Answer» Hello everyone.
I am trying to make a .bat file that reads the individual lines of a .txt file, and then, CREATES a new .txt file. I am doing this because i am trying to automate an extremely repetitive scheduling task.
For example, I have a file named project.txt which has several lines, and it looks like this:
Firstidea Secondidea Thirdidea Fourthidea Fifthidea Sixthidea Seventhidea …..(and so on)
Im trying to make a .bat file that will read the file above and create a new file, called projectschedule.txt, that will look like this:
4 firstidea
1
0
4 secondidea
1
0
4 thirdidea
1
0
…….And so on.
So, the section from will reference the first line of the project.txt file. The section of will reference the 2nd line of the project.txt file The section of will reference the 3rd line of the project.txt file The section of will reference the 4TH line of the project.txt file The section of will reference the 5th line of the project.txt file
And so on for each line in the project.txt file.
The project.txt file that the .bat file will be referencing can have hundreds of lines. How can I make a for loop to reference each individual line of the project.txt file to make an output file called projectschedule.txt that looks similar to above?
I am thinking that the loop will look something like this:
@ECHO off setlocal enabledelayedexpansion cd /d "C:\Users\John\Desktop\schedule" set /a sched=0 for /f "delims=" %%A in (project.txt) do ( echo > projectschedule.txt echo 4 >> projectschedule.txt echo firstidea >> projectschedule.txt echo >> projectschedule.txt echo >> projectschedule.txt echo 1 >> projectschedule.txt echo >> projectschedule.txt echo >> projectschedule.txt echo >> projectschedule.txt echo 0 >> projectschedule.txt echo >> projectschedule.txt echo >> projectschedule.txt sched=!sched!+3 )
I am new to batch, and i had a lot of help developing a similar batch from a forum a member named Salmon Trout.
The code above does not work. Part of the reason is because my output text needs to have < and > symbols.
-----echo firstidea >> projectschedule.txt Also, the string above is the 8th line of the large code above. This string of code needs output the next consecutive line of the project.txt file each time it is looped through. Currently, the code above will only output"firstidea" every time it is looped through.
Any ideas or help would be greatly appreciated. Hello,
Thank you for the input.
The code you sent above works great!
The line that helped out the most was
echo ^%%i^ >> projectschedule.txt inside of the do() loop, as i did not know how to reference each invidiviual line of the project.txt file as the loop was running.
Thanks again!
|