Split text file at start marker and blank line or just start marker into multiple files
Posted: 05 Jan 2019 06:44
I am trying to decide the best way of splitting the following single .rc file into mutiple files.
The start of each split are the lines where the first column is a number and the second column begins with the word DIALOG
The end of each split should be either a blank line or another start line (in case the blank line is missing)
Each filename should be the first column (number) from each start line eg. 1003.rc
This is the code I have so far, but I don't think I need to store the line numbers, also the output files should still contain the original blank lines
The following example should create four files named 1003.rc 1004.rc 1005.rc 1006.rc
Any help would be greatly appreciated
The start of each split are the lines where the first column is a number and the second column begins with the word DIALOG
The end of each split should be either a blank line or another start line (in case the blank line is missing)
Each filename should be the first column (number) from each start line eg. 1003.rc
This is the code I have so far, but I don't think I need to store the line numbers, also the output files should still contain the original blank lines
Code: Select all
set i=0
for /f "tokens=1,2 delims=: " %%A in ('^(type "Dialog.rc" ^| "%SystemRoot%\System32\findstr.exe" /b /n /r "^[1-9][0-9]* DIALOG"^) 2^>nul') do (
set /a i+=1
set array_line[!i!]=%%A
set array_name[!i!]=%%B
)
Any help would be greatly appreciated
Code: Select all
1003 DIALOGEX 0, 0, 227, 93
STYLE DS_SHELLFONT | DS_MODALFRAME | DS_NOIDLEMSG | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Run"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 9, "Segoe UI"
{
CONTROL 160, 12297, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE, 7, 11, 21, 20
CONTROL "Type the name of a program, folder, document, or Internet resource, and Windows will open it for you.", 12289, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 36, 11, 182, 22
CONTROL "&Open:", 12305, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 7, 39, 24, 10
CONTROL "", 12298, COMBOBOX, CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 36, 37, 183, 200
CONTROL "Run in separate &memory space", 12306, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 40, 50, 183, 10
CONTROL "OK", 1, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 62, 70, 50, 14
CONTROL "Cancel", 2, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 116, 70, 50, 14
CONTROL "&Browse...", 12288, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 170, 70, 50, 14
}
1004 DIALOGEX 20, 20, 227, 69
STYLE DS_SHELLFONT | DS_MODALFRAME | DS_NOIDLEMSG | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Missing Shortcut"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 8, "MS Shell Dlg"
{
CONTROL 134, -1, STATIC, SS_ICON | SS_REALSIZECONTROL | WS_CHILD | WS_VISIBLE, 7, 7, 21, 20
CONTROL "Windows is searching for %s. To locate the file yourself, click Browse.", 102, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 35, 7, 187, 30
CONTROL "Cancel", 2, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 169, 47, 50, 14
CONTROL "&Browse...", 12288, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 115, 47, 50, 14
}
1005 DIALOGEX 0, 0, 259, 75
STYLE DS_SHELLFONT | DS_MODALFRAME | DS_NOIDLEMSG | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Run"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 9, "Segoe UI"
{
CONTROL 160, 12297, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE, 7, 3, 16, 16
CONTROL "Type the name of a program, folder, document, or Internet resource", 12289, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 40, 7, 212, 11
CONTROL "&Open:", 12305, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 7, 25, 32, 8
CONTROL "", 12298, COMBOBOX, CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 40, 22, 210, 200
CONTROL "Run in separate &memory space", 12306, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP, 7, 55, 97, 10
CONTROL "", 12326, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE, 40, 37, 16, 16
CONTROL "This task will be created with administrative privileges.", 12327, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 54, 38, 200, 11
CONTROL "OK", 1, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 108, 54, 45, 14
CONTROL "Cancel", 2, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 157, 54, 45, 14
CONTROL "&Browse...", 12288, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 205, 54, 45, 14
}
1006 DIALOG 0, 0, 240, 55
FONT 9, "Segoe UI"
{
CONTROL 160, 12297, STATIC, SS_ICON | WS_CHILD | WS_VISIBLE, 7, 3, 16, 16
CONTROL "Type the name of a program, folder, document, or Internet resource", 12289, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 40, 7, 212, 11
}