My slightly different variation... it just extracts any lines matching the regular expression directly into a new buffer. No need to perform the selective display first.
I end up parsing huge (15+ meg) log files by hand, and wanted to pull out information. Selective display was alright, but I would need to end up turning on selective display, copying the lines, opening a new buffer, pasting the result in, turning selective display off, then repeating for each set of data. Thus, this macro was born.
_command UTLExtractLines()
{
int SourceWindow;
int DestWindow;
Done = false;
/* Get the string to search for. */
if ((get_string(SearchStr, "RegEx to extract:") == 0) &&
(SearchStr != ''))
{
/* Grab a pointer to the source window. */
SourceWindow = p_active_form;
/* Make a new file, and grab its pointer too. It became active by
default. */
new_file();
DestWindow = p_active_form;
/* Save our current position in the source window. */
SourceWindow.save_pos(OrigPos);
SourceWindow.top();
do
{
if (SourceWindow.search(SearchStr, "R<") == 0)
{
SourceWindow.get_line(CurrentLine);
DestWindow._insert_text(CurrentLine"\n");
}
else
{
Done = true;
}
}
while ((SourceWindow.down() == 0) && (Done == false))
/* Finally, restore our original position in the source window. */
SourceWindow.restore_pos(OrigPos);
}
}