Thanks so much for you assistance!!!!
I got it to working, this is the code:
Code: Select all
/* findValueFromSourceInTarget.js
Script reads through source file, and finds matching 3rd column in target
Then writes complete line from target to a another window.
ALL files should be in open tabs. If you do not want to hard code the file names,
then use the relational tab numbers for the files you have open */
var sourceFileTab = 2; /* seed with window tab# file is in */
var targetFileTab = 3; /* seed with window tab# file is in */
var outputFoundTab = 4; /* seed with window tab# for writing found data */
var debugTab = 5; /* seed with window tab# for writing debug data */
var colSep = String.fromCharCode(9); /* TAB character */
var LF = String.fromCharCode(13); /* LineFeed character */
UltraEdit.unixReOn(); /* designate regexp syntax style */
// Validate that UES windows to use are open are open */
if( (sourceFileTab!=-1) && (targetFileTab!=-1) && (outputFoundTab!=-1) && (debugTab!=-1) )
findValueFromSourceFileInTargetFile();
/* Function to get 3rd col from source file and find in 3rd col in target file and
write complete line it was found on to output tab */
function findValueFromSourceFileInTargetFile() {
var sourceFile = UltraEdit.document[sourceFileTab];
var targetFile = UltraEdit.document[targetFileTab];
var outputFile = UltraEdit.document[outputFoundTab];
var debugFile = UltraEdit.document[debugTab];
sourceFile.findReplace.regExp = true;
targetFile.findReplace.regExp = true;
var sourceFind = "^[A-Z]+\\t[\"0-9]+\\t[\"0-9]+\\t";
sourceFile.top();
while ( (sourceFile.findReplace.find(sourceFind)) && ! sourceFile.isEof() ) {
var sourceHit = sourceFile.selection; /* value found in sourcefile */
debugFile.write(sourceHit.concat(LF)); /* write info to debug tab */
var cols = sourceHit.split(colSep); /* extract delimited cols into array elements */
debugFile.write(cols[2].concat(LF)); /* write info to debug tab */
/* search key from sourcefile- .start @beginning of each row
.then match any Uppercase letters until a TAB
.then match TAB
.then match double quotes and digits 0-9 until a TAB
.then match value extracted from sourcefile ex. "191909"
.then match TAB */
var targetFind = "^[A-Z]+\\t[\"0-9]+\\t"+cols[2]+"\\t";
debugFile.write(targetFind.concat(LF)); /* write info to debug tab */
debugFile.write(LF);
targetFile.top();
if ( targetFile.findReplace.find(targetFind) ) {
targetFile.selectLine();
var targetHit = targetFile.selection;
outputFile.bottom();
outputFile.write(targetHit); /* write complete row that info was found on to output tab */
} else {
debugFile.write("Not found in Target!!!!"); /* write error to debug tab */
}
}
}
But it is SO slow, it took over an hour to process 1254 rows, for the source file I have 1254 rows, so I pasted the same rows in the target, so obviously it found 1254 matches and correctly wrote those rows to the "output" tab.
Well I say correctly, NOT exactly, It always drops the first TAB( it is right after the word "UPDATE" ) on a row on all rows written
except for the first row, for example this is the first 5 rows in the sourcefile:
Code: Select all
UPDATE "99883" "191909" "SHELEY ENTERPRISES"
UPDATE "99885" "651429" "COLD WATER INDUSTRIES"
UPDATE "21090" "434957" "ADVANCED MAILING SVC"
UPDATE "21090" "428918" "EINS SERVICES"
UPDATE "21090" "650297" "GOLD STAR PEST CONTROL INC"
This is the first 5 rows it wrote to the "output" tab, notice the first TAB is missing on ALL rows except the first row:
Code: Select all
UPDATE "99883" "191909" "SHELEY ENTERPRISES"
UPDATE"99885" "651429" "COLD WATER INDUSTRIES"
UPDATE"21090" "434957" "ADVANCED MAILING SVC"
UPDATE"21090" "428918" "EINS SERVICES"
UPDATE"21090" "650297" "GOLD STAR PEST CONTROL INC"
I don't need to do this alot so I went ahead and just extracted the third column from both the source file and target file and created two tables in an oracle database to do the matching because this method is so SLOW.
I was just trying to create a generic utility for doing this type of matching on flat files that are delimited( i.e. TAB, comma, pipe, etc. ).
Is there a different search/match method I can use to speed it up?
Would it run faster if I did it in a UE macro?
Again Thanks very much for your assistance!!!