Hi,
I need to move the rows of data from my c:\main.txt file and create a new text file named based on three digits of the line. The newly created file to be saved in D:\Records\(particular folder). The folders on the last digits are there in D:\Records. The data in main.txt is numeric.
Data Sample (main.txt)
1154720520034900200434500900000000353000100099010 0
1155720520035000200434600900000000764600100099010 0
1205201422628018546001034000000061060044000099012 0
1305201422627928224009117000000015940044000069020 0
The above sample data will create 3 new files
(1) 010.txt and saved at D:\Records\010
1154720520034900200434500900000000353000100099010 0
1155720520035000200434600900000000764600100099010 0
(2) 012.txt and saved at D:\Records\012
1205201422628018546001034000000061060044000099012 0
(3) 020.txt and saved at D:\Records\020
1305201422627928224009117000000015940044000069020 0
Thanks in advance.
Move data and create new file
Moderator: DosItHelp
Re: Move data and create new file
This may help:
penpen
Edit: No debug verson & patched: Forgotten to create the subfolder.
Code: Select all
@echo off
setlocal enableDelayedExpansion
for /F "tokens=* usebackq delims=" %%a in ("main.txt") do (
set "line=%%~a"
set "location=D:\Records\!line:~-5,3!"
set "file=!location!\!line:~-5,3!.txt"
mkdir "!location!" 2>nul
(echo(!line!)>>"!file!"
)
endlocal
exit /B 0
penpen
Edit: No debug verson & patched: Forgotten to create the subfolder.
Last edited by penpen on 18 May 2014 23:43, edited 1 time in total.
Re: Move data and create new file
Hi,
I tried, but it does not create the text files & I need to save them in D:\Records\(particular folder)xxx.txt
(1) 010.txt and saved at D:\Records\010\010.txt
Thanks.
I tried, but it does not create the text files & I need to save them in D:\Records\(particular folder)xxx.txt
(1) 010.txt and saved at D:\Records\010\010.txt
Thanks.
Re: Move data and create new file
I've changed the code above:
I've forgotten to create the (sub)folders (i just have overseen this part of the task, sorry).
The above code is no debug version anymore (so it should create the files instead of displaying it).
penpen
I've forgotten to create the (sub)folders (i just have overseen this part of the task, sorry).
The above code is no debug version anymore (so it should create the files instead of displaying it).
penpen
Re: Move data and create new file
Hi,
Thanks Penpen its perfect.
Thanks.
Thanks Penpen its perfect.
Thanks.