Help needed for Find and Replace
Hi,
I am trying to find and replace the words from .txt file to indesign contents. If i have repeated words in .txt file the indesign also did for 3 times. The below image illustrates much better. Sorry i am improving my english to convey the requirement better. ![]()

Script Tried:
myfndchange();
function myfndchange(){
var myFolder = File.openDialog("Select the TXT file to Proceed",isSupportedTXT,true);
if(myFolder!=null){FilePath=decodeURI(myFolder);}
if(myFolder==null){return;}
var datafile = new File(FilePath);
datafile.open('r') ;
while (!datafile.eof){
strLineIn = datafile.readln();
colorArray = strLineIn.split("\t");
var myColumn1=colorArray[0];
var myColumn2=colorArray[1];
var flag=0;
x=myColumn1.split(" ");
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeLockedLayersForFind = true;
app.findChangeTextOptions.includeLockedStoriesForFind = true;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeMasterPages = true;
app.findChangeTextOptions.includeFootnotes = true;
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.wholeWord = true;
mydoc=app.documents[0];
app.findTextPreferences = null; app.changeTextPreferences = null;
app.findTextPreferences.findWhat=myColumn1;
var myfound=mydoc.findText();
for(i=0;i<myfound.length;i++){
if(myfound.words.length===x.length){
app.changeTextPreferences.changeTo = myColumn1+"/"+myColumn2;
myfound.changeText()
}
}
}
}
function isSupportedTXT(file) {
try {
if (file instanceof Folder)
return true;
else
return file.name.match(/\.txt$/i) != null;
} catch (e) {
alert("Error in isSupported method: " + e);
}
}
Thanks,
K