Wow ... 400 MB! That's a very important info. My first macro modifies the source file and when finished, it restores it by closing without saving and reopening it. That's okay for normal files, but not for a 400 MB file which is hopefully opened without a temp file and so all changes are permanent.
I have changed some lines in the macro to work now without modifying the source file. This should increase the speed of the macro a lot.
The macro contains some additional commands to make sure it works independent of the configuration options
Home Key Always Goto Column 1 and
Bookmark column with line (second currently only for UEStudio 6.00+, will be available in UE in next major release). It's also independent of the current regular expression engine because it is regex free.
How it works:
First the macro verifies if the last line of the source file is terminated with EOL character(s). This is important because the macro contains Key DOWN ARROW with IfEof and this would produce an endless loop if the last line of the file is not terminated because Key DOWN ARROW does not work and so end of file is never reached. That's the only possible modification of the source file!
The macros works with 2 bookmarks now. So next it clears every existing bookmark if there is any.
Next it selects in the first line the date string and copies it to user clipboard 9. I have inserted the
red lines to show you how to select the date string if it is not at end of a line.
Find Up Select ";" selects from current cursor position till the found string with including the found string. Because the ';' should be not included in the file name the select mode is started before this special find with selecting and so Key RIGHT ARROW is executed in select mode which reduces the selected string by the ';'.
Find Select "" is the same as when you hold the SHIFT key while pressing the
Find Next button in the find dialog.
Key RIGHT ARROW moves the cursor once right to make sure, that the just copied string is not found again in the following loop (not really needed but more secure).
The main loop always searches for the current date string in clipboard 9.
If it is found again, unselect the found string and move cursor once left before continue search. Well, this is not really needed, but it's better for security.
If the date string in clipboard 9 is not found, the cursor is in the last line with this date string. Set the cursor now to start of the next line and bookmark this line. That would fail at the last line of the file if it would not be terminated with CRLF (or only LF or only CR depending on the file format and current edit mode).
Next clipboard 8 is selected and from current cursor position till previous bookmark everything is selected (same as pressing Shift+F2 for Search - Next Bookmark with selecting).
Copy the selected block into clipboard 8, clear the bookmark here and move the cursor down to the remaining bookmark where the next date block starts.
Then open a new file, paste the block, move cursor to top, insert here the date string and inser (=append) ".csv" to get the file name. Select the file name, cut it from the file, save the new file with "date string.csv" and close it.
Back in the source file check if end of file is reached. If so, exit the loop. If not, again select in the already bookmarked line the new date string, copy it to clipboard 9, set cursor to a new position in the current line where the date string cannot be found again and continue the loop.
After the loop clear the remaining bookmark at end of the file, clear the 2 used clipboards to free RAM and switch back to the windows clipboard.
Once again: The macro property
Continue if a Find with Replace not found must be checked for this macro. And because of the focus issue after closing a file described at
Problem with Previous Window/Tab Command make sure you have only your CSV file open or it is the most right file in the open file tabs order.
InsertMode
ColumnModeOff
HexOff
Bottom
IfColNum 1
Else
"
"
EndIf
Loop
GotoBookMark
IfEof
ExitLoop
Else
ToggleBookmark
Bottom
EndIf
EndLoop
Top
ToggleBookmark
Clipboard 9
Key END
Find Up ";"
Find Up ";"
Key LEFT ARROW
StartSelect
Find Up Select ";"
Key RIGHT ARROW
Copy
EndSelect
Key RIGHT ARROW
Loop
Find "^c"
IfFound
Key LEFT ARROW
Else
Key HOME
IfColNumGt 1
Key HOME
EndIf
Key DOWN ARROW
ToggleBookmark
Clipboard 8
GotoBookMarkSelect
Copy
EndSelect
ToggleBookmark
GotoBookMark
NewFile
Paste
Top
Clipboard 9
Paste
".csv"
SelectToTop
Cut
SaveAs "^c"
CloseFile
IfEof
ExitLoop
Else
Key END
Find Up ";"
Find Up ";"
Key LEFT ARROW
StartSelect
Find Up Select ";"
Key RIGHT ARROW
Copy
EndSelect
Key RIGHT ARROW
EndIf
EndIf
EndLoop
ToggleBookmark
ClearClipboard
Clipboard 8
ClearClipboard
Clipboard 0