Copy link to clipboard
Copied
Hi Everyone,
I have a TSV(tabbed delimited file) document which contains customer name and updates.
I need to find the customer name and get appropriate the updates from next column. I tried and get the partial answer(see the screenshot).
Please anyone suggest me to find the solution.
TSV Data
Code:
var xlData=[];
alert(GetCustUpdates("Customer 1"));
function GetCustUpdates(CustID){
var datafile = new File("~/Desktop/Updates.tsv");
if (datafile.exists){
datafile.open('r') ;
while (!datafile.eof){
strLineIn = datafile.readln();
colorArray = strLineIn.split("\t");
if (colorArray[0]!="" && colorArray[1]!=""){
if(colorArray[0].indexOf(CustID)!=-1){
xlData.push(colorArray[1]);
}
}//if loop
}//While loop
return xlData;
}//IF data exisist
}
OutPut:
-yajiv
This would be a more roundabout way that would probably take a longer time, still …
...
var theText = readTSV ("~/Desktop/Updates.tsv", "Customer 1");
alert (theText.join("\n"));
////// read tsv file //////
function readTSV (thePath, CustID) {
if (File(thePath).exists == true) {
var file = File(thePath);
file.open("r");
file.encoding= 'BINARY';
var theArray = new Array;
// collect text;
while (!file.eof){
strLineIn = file.readln();
var colorArray = strLineIn.split("\t");
if (colorArray.length == 2){
theArray.push(
Copy link to clipboard
Copied
Hi EveryOne,
Any updates/suggestion on the above request/post.
Copy link to clipboard
Copied
Your update clumn has some lines, So you need to fetch next line until last " character.
below is rewrited your code but not tested.
var xlData=[];
var re = /.+"$/;
var tmp = "";
alert(GetCustUpdates("Customer 1"));
function GetCustUpdates(CustID){
var datafile = new File("~/Desktop/Updates.tsv");
if (datafile.exists){
datafile.open('r') ;
while (!datafile.eof){
strLineIn = datafile.readln();
colorArray = strLineIn.split("\t");
if (colorArray.length==2){
tmp = colorArray[1];
}
else if (colorArray.length==1){
tmp += "\n" + colorArray[0];
if (colorArray[0].match(re)!=null) xData.push(tmp);
tmp = "";
}
}//While loop
return xlData;
}//IF data exisist
}
Copy link to clipboard
Copied
Hi Ten A,
Thank for the prompt response. the received output is not as expected.
Output as Expected:
Output as Received:
-yajiv
Copy link to clipboard
Copied
Can you provide an exemplary TSV file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
This would be a more roundabout way that would probably take a longer time, still …
var theText = readTSV ("~/Desktop/Updates.tsv", "Customer 1");
alert (theText.join("\n"));
////// read tsv file //////
function readTSV (thePath, CustID) {
if (File(thePath).exists == true) {
var file = File(thePath);
file.open("r");
file.encoding= 'BINARY';
var theArray = new Array;
// collect text;
while (!file.eof){
strLineIn = file.readln();
var colorArray = strLineIn.split("\t");
if (colorArray.length == 2){
theArray.push([colorArray[0], colorArray[1]])
}
else {
theArray[theArray.length - 1][1] = theArray[theArray.length - 1][1].concat("\r"+strLineIn)
};
};//While loop
file.close();
// check for one specific customer;
var thisArray = [CustID + " not found"];
for (var m = 0; m < theArray.length; m++) {if (theArray
[0].indexOf(CustID) != -1) {thisArray = theArray }}; return thisArray
}
};
Copy link to clipboard
Copied
Hi c.pfaffenbichler,
This what I expected and much appreciated work..
@Ten A- Thank you for the knowledge contribution and response.
-yajiv