Example, here are 2 rows of data:
- Code: Select all
123 12 12345
12 123 12345
I want to reformat it to:
- Code: Select all
123 12 12345
12 123 12345
So the columns are still lined up but there is only 1 space after the widest value in a column.
Welcome to the IDM Forum. This forum is meant as a user-to-user support mechanism where users can share knowledge and tips for all IDM software.
Since these forums are user-to-user based, IDM does not regularly read or reply to the posts in this forum. For problem reports, suggestions, or feature requests, you must email us directly. Our trained technical support staff answers most inquiries within 30 minutes.
123 12 12345
12 123 12345123 12 12345
12 123 12345
Mofi wrote:Alternatively you could convert all spaces to tabs the get a character separated value file (CSV file) with the tab as separator by using a regular expression search searching for " +" (without the double quotes, i.e. space plus) and replace all occurrences with ^t (UE regexp) or \t (Unix/Perl regexp). Next use the command Column - Convert to Fixed Column. But the result would be slightly different because then all "field values" in the "columns" would be left aligned.
function DeleteMultipleBlankColumns()
{
UltraEdit.ueReOn();
UltraEdit.insertMode();
UltraEdit.columnModeOff();
// Set the cursor to last non whitespace character at end of file and
// get the number of the line containing the last non whitespace char.
UltraEdit.activeDocument.bottom();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchAscii=false;
UltraEdit.activeDocument.findReplace.searchDown=false;
UltraEdit.activeDocument.findReplace.searchInColumn=false;
UltraEdit.activeDocument.findReplace.find("[~ ^t^r^n^b]");
if (UltraEdit.activeDocument.isNotFound()) return;
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.key("END");
// Inserting the following text should make the last line longer than all other lines.
UltraEdit.activeDocument.write(" <InSeRtEd>");
var nNumberOfLastLine = UltraEdit.activeDocument.currentLineNum;
// Move cursor to top of file and delete all trailing spaces in the file.
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.trimTrailingSpaces();
// For ignoring blank lines at top of the file search for first non
// whitespace character at top of the file and remember the number
// of the line where this non whitespace character was found.
UltraEdit.activeDocument.findReplace.find("[~ ^t^r^n^b]");
UltraEdit.activeDocument.key("HOME");
var nNumberOfFirstLine = UltraEdit.activeDocument.currentLineNum;
// Enable column editing mode and set search option
// to run all further searches in selected text only.
UltraEdit.columnModeOn();
UltraEdit.activeDocument.findReplace.mode=1;
// Blank columns on most left side are always completely deleted.
var bFirstBlankColumnFound = true;
// For every character on the first non blank line.
var nColumn = 0;
while(!UltraEdit.activeDocument.isChar("\r") && !UltraEdit.activeDocument.isChar("\n")) {
UltraEdit.activeDocument.gotoLine(nNumberOfFirstLine,++nColumn);
// Is the character NOT a space, nothing to do on this column.
if (!UltraEdit.activeDocument.isChar(" ")) {
bFirstBlankColumnFound = false;
continue;
}
// Select to next column of last line resulting in selecting this column.
UltraEdit.activeDocument.gotoLineSelect(nNumberOfLastLine,nColumn+1);
// Run a regular expression search to check if there is any non whitespace
// character in the selected column which results in keeping the column as is.
UltraEdit.activeDocument.findReplace.find("[~ ^t^r^n^b]");
var bNonSpace = UltraEdit.activeDocument.isFound();
UltraEdit.activeDocument.endSelect();
if (bNonSpace) continue;
// The column contains only spaces. Delete this column, except
// it is the first blank column which must be always kept.
if (!bFirstBlankColumnFound) bFirstBlankColumnFound = true;
else {
UltraEdit.activeDocument.gotoLine(nNumberOfFirstLine,nColumn--);
UltraEdit.activeDocument.columnDelete(1);
}
}
// Turn off column editing mode, delete the inserted text at bottom of the
// file and go back to top of the file before exiting this script function.
UltraEdit.columnModeOff();
UltraEdit.activeDocument.findReplace.matchCase=true;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.find(" +<InSeRtEd>");
UltraEdit.activeDocument.deleteText();
UltraEdit.activeDocument.top();
}
if (UltraEdit.document.length > 0) {
DeleteMultipleBlankColumns();
}