Normally such a text inserting is done manually by activating the column mode, for example with Alt+C, selecting the lines at the column where the text should be inserted, simply type the text or use Column - Insert/Fill Columns and turn off column mode by pressing again Alt+C. I normally need less than 5-10 seconds for such a text inserting.
But maybe you want to do it with a script because it is only a part of other actions you do with a script. Because I still don't know your version of UltraEdit and the regular expression engine you prefer, I developed a solution which works without any find/replace operation.
The advantage of this solution is that you can undo the changes by the script with a single Ctrl+Z (one undo step) because the source file is modified only by one paste command.
The disadvantages are that it is not the fastest method and it can destroy data if the source file is a Unicode file, but new files are created by default as ASCII. You would need extra script code to avoid wrong data copying between the source file and the new file which is temporarily used in that case. Also this method could insert the text in the wrong column (68 instead of 67) depending on your version of UltraEdit. I have not added the workaround code for the affected versions of UltraEdit which set the cursor in the first line of a Unicode file with BOM to the wrong column because it counts the invisible BOM as character in the line too. However, I guess your files are ASCII/ANSI files and so the simplest version will be enough.
You have to insert the function
getActiveDocumentIndex at top of this script to be able to use it. I tested this script with UE v14.00b+1 with some examples I created myself.
Code: Select all
if (UltraEdit.document.length > 0)
{
if (UltraEdit.activeDocument.isSel()) {
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.selectClipboard(9);
UltraEdit.activeDocument.copy();
var iActiveIndex = getActiveDocumentIndex();
UltraEdit.newFile();
UltraEdit.activeDocument.paste();
var bLastLineTerminated = false;
if (UltraEdit.activeDocument.isColNum(1)) bLastLineTerminated = true;
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.key("END");
if (UltraEdit.activeDocument.isColNumGt(66)) {
UltraEdit.activeDocument.gotoLine(1,67);
} else {
do UltraEdit.activeDocument.write(" ");
while (!UltraEdit.activeDocument.isColNum(67))
}
if (typeof(UltraEdit.columnModeOn) == "function") UltraEdit.columnModeOn();
else if (typeof(UltraEdit.activeDocument.columnModeOn) == "function") UltraEdit.activeDocument.columnModeOn();
UltraEdit.activeDocument.columnInsert("A0001");
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
if (bLastLineTerminated) {
UltraEdit.activeDocument.bottom();
UltraEdit.activeDocument.deleteToStartOfLine();
}
UltraEdit.activeDocument.selectAll();
UltraEdit.activeDocument.copy();
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
UltraEdit.document[iActiveIndex].setActive();
UltraEdit.activeDocument.paste();
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
}
}