Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

is possible to read TSV text(paragraph) content?

Engaged ,
Jan 11, 2017 Jan 11, 2017

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

Screen Shot 2017-01-11 at 4.57.06 pm.png

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:

Screen Shot 2017-01-11 at 4.59.15 pm.png

-yajiv

TOPICS
Actions and scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 12, 2017 Jan 12, 2017

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(

...
Translate
Adobe
Engaged ,
Jan 11, 2017 Jan 11, 2017

Hi EveryOne,

Any updates/suggestion on the above request/post.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2017 Jan 12, 2017

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 12, 2017 Jan 12, 2017

Hi Ten A,

Thank for the prompt response. the received output is not as expected.

Output as Expected:

Screen Shot 2017-01-12 at 3.49.46 pm.png

Output as Received:

Screen Shot 2017-01-12 at 3.48.51 pm.png

-yajiv

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Can you provide an exemplary TSV file?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 12, 2017 Jan 12, 2017

Hi Chrish,

Please find the below link.

https://app.box.com/s/krrlmjsmrov4rnvb6jfxs0t9785kecuj

-yajiv

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2017 Jan 12, 2017

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

}

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 12, 2017 Jan 12, 2017
LATEST

Hi c.pfaffenbichler,

This what I expected and much appreciated work..

@Ten A- Thank you for the knowledge contribution and response.

-yajiv

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines