file splitting
Posted: 09 Mar 2011 10:18
I need to split a master text file into multiple text files based on user name. I have a script that does the job but it splits the file based on the last character instead of the user name. If the user name is repeated it needs to append to the same file.
master file's content is such:
==================================================
Directory of Y:\DDAN\Desktop Backups\2010-02-27
26/08/2009 09:53 AM 4,707,780 101_0159.AVI
26/08/2009 09:54 AM 6,794,386 102_0213.AVI
2 File(s) 11,502,166 bytes
Directory of Y:\SJOHN\My Pictures\typo
01/11/2009 09:11 AM 21,874,732 Pictures Misc 2009 098.avi
1 File(s) 21,874,732 bytes
===================================================
Just need to modify the script so it splits based on user name. Any questions or uncertainties feel free to ask. Thanks
@echo off & setLocal EnableDELAYedExpansion
if exist file?.txt del file?.txt
for /f "tokens=* delims= " %%a in (masterfile.txt) do (
set str=%%a
echo !str! | find "Directory of" > nul
if not errorlevel 1 (
set dest=!str!
if defined dest set dest=!dest:~-1!
)
if defined dest echo !str!>> file!dest!.txt
)
master file's content is such:
==================================================
Directory of Y:\DDAN\Desktop Backups\2010-02-27
26/08/2009 09:53 AM 4,707,780 101_0159.AVI
26/08/2009 09:54 AM 6,794,386 102_0213.AVI
2 File(s) 11,502,166 bytes
Directory of Y:\SJOHN\My Pictures\typo
01/11/2009 09:11 AM 21,874,732 Pictures Misc 2009 098.avi
1 File(s) 21,874,732 bytes
===================================================
Just need to modify the script so it splits based on user name. Any questions or uncertainties feel free to ask. Thanks
@echo off & setLocal EnableDELAYedExpansion
if exist file?.txt del file?.txt
for /f "tokens=* delims= " %%a in (masterfile.txt) do (
set str=%%a
echo !str! | find "Directory of" > nul
if not errorlevel 1 (
set dest=!str!
if defined dest set dest=!dest:~-1!
)
if defined dest echo !str!>> file!dest!.txt
)