Here is the script to copy all lines containing a string from a list of strings in a second file into the Windows clipboard. There were originally only 6 lines inserted and 1 deleted in comparison to the referenced script which deletes the lines with the found string. In the meantime additional lines were inserted for impoving speed, see my next post.
Special meaning of ^c is documented on help page of the Find command and means simply content of active clipboard, clipboard 9 for this script for the searches.
- Code: Select all
// Document 0 (most left one) must be the active document.
// Document 1 (second file right to active file) must be the file with the strings.
if ((UltraEdit.document.length >= 2) && (UltraEdit.activeDocument.path == UltraEdit.document[0].path)) {
// Always specify the search engine which should be used.
UltraEdit.ueReOn();
UltraEdit.selectClipboard(0);
UltraEdit.clearClipboard();
// Use a clipboard instead of a string variable in
// case of file with the strings is a Unicode file.
UltraEdit.selectClipboard(9);
// Open a new file which automatically gets the active one. If the document
// windows are maximized this new file avoids display updates on the file
// to search for the strings which makes execution of the script faster.
UltraEdit.newFile();
/* Verify if the last line of the file with the strings has a line ending.
If this is not the case insert one and make sure that the auto indent
feature has not added additional preceding white-spaces. The last line
of the file with the strings must have a line ending or the script
would run into an endless loop because cursor does never reach the
end of the file with the strings. */
UltraEdit.document[1].bottom();
if (UltraEdit.document[1].isColNumGt(1)) {
UltraEdit.document[1].insertLine();
if (UltraEdit.document[1].isColNumGt(1)) {
UltraEdit.document[1].deleteToStartOfLine();
}
}
UltraEdit.document[1].top();
// For security same check also on the active file.
UltraEdit.document[0].bottom();
if (UltraEdit.document[0].isColNumGt(1)) {
UltraEdit.document[0].insertLine();
if (UltraEdit.document[0].isColNumGt(1)) {
UltraEdit.document[0].deleteToStartOfLine();
}
}
// Specify once all the find options.
UltraEdit.document[0].findReplace.searchDown=true;
UltraEdit.document[0].findReplace.mode=0;
UltraEdit.document[0].findReplace.matchCase=false;
UltraEdit.document[0].findReplace.matchWord=false;
UltraEdit.document[0].findReplace.regExp=false;
// Open the output window when not already visible.
// if (UltraEdit.outputWindow.visible == false) UltraEdit.outputWindow.showWindow(true);
// Loop through the lines of the file with the strings.
while(!UltraEdit.document[1].isEof()) {
UltraEdit.document[1].startSelect();
UltraEdit.document[1].key("END");
if (UltraEdit.document[1].isSel()) {
UltraEdit.document[1].copy();
UltraEdit.document[1].endSelect();
UltraEdit.document[1].key("HOME");
UltraEdit.document[1].key("DOWN ARROW");
}
else {
// Ignore empty lines!
UltraEdit.document[1].endSelect();
UltraEdit.document[1].key("HOME");
UltraEdit.document[1].key("DOWN ARROW");
continue;
}
// UltraEdit.outputWindow.write("Searching for \""+UltraEdit.clipboardContent+"\"");
// Start at the beginning of the file.
UltraEdit.document[0].top();
while(UltraEdit.document[0].findReplace.find("^c")) {
UltraEdit.selectClipboard(0);
UltraEdit.document[0].selectLine();
UltraEdit.document[0].copyAppend();
UltraEdit.selectClipboard(9);
}
}
UltraEdit.document[0].top();
UltraEdit.document[1].top();
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
// Remove the comments on the 3 lines below to save the found
// lines into the file specified in the saveAs command.
// UltraEdit.activeDocument.paste();
// UltraEdit.saveAs("Full Path\\Filename.ext");
// UltraEdit.clearClipboard();
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
UltraEdit.document[0].setActive();
}