Solved Dynamically adding a file name to a .txt file

August 16, 2017 at 10:25:16
Specs: Windows 10
Hi All,

I am new to batch scripting, need some inputs on how to achieve the below. I tried googling but I am not sure how to start writing a batch script for the below, please provide with some ideas.

I have two files master.txt and child.txt.

Master.txt has a fixed format as below
JobName :- Load EIM Tables
Date :- Load Date
File Name :- $$FileName

Child.txt has the below format

FileName1
FileName2
FileName3
.........
.........
.........
FileName800

I am trying to write a script, which should take one FileName from child.txt and replace the $$FileName in master.txt and delete the same file name from child.txt

for example if I run the script for the first time, the master.txt should me
JobName :- Load EIM Tables
Date :- Load Date
File Name :- FileName1

And for the second run
JobName :- Load EIM Tables
Date :- Load Date
File Name :- FileName2

And when all the files in child.txt are processed, the master.txt has to be deleted.

Please help with some ideas on how to achieve this.

Thanks & Regards,
Annie.



See More: Dynamically adding a file name to a .txt file

Reply ↓  Report •

#1
August 16, 2017 at 18:31:47
✔ Best Answer
Is this (Load Date) static or dynamic?
Date :- Load Date
And is there other content to "master" other than these lines? (Apologies in advance, I'm kind of used to people coming back with "OH, there's 356 other lines...)
If not:
:: begin batch script
@echo off & setlocal
set f=
set /p f=<child.txt
if not defined f (
echo end of file child.txt
echo delete master.txt...
pause
delete master.txt
goto :eof
)
>master.txt (
echo JobName :- Load EIM Tables
echo Date :- Load Date
echo File Name :- %f%
)
find /v "%f%"<child.txt>temp
move /y temp child.txt
::========= end batch
Obviously, make sure the temp filename is something innocuous. Also advisable to back up child.txt (or whatever it is) before any operations since it gets depleted.

Reply ↓  Report •
Related Solutions


Ask Question