Robotic Process Automation (RPA)

 View Only
Expand all | Collapse all

Write table to file using tab as delimiter

  • 1.  Write table to file using tab as delimiter

    Posted Fri April 14, 2023 12:28 PM

    Hello, everybody.

    I need to use the command write a table to a txt file, this file needs to be separated by tabs. ¿How can I do that? I can't directly enter the tab in the parameter and I tried with scape characters like \t.

    Thank you.



    ------------------------------
    Jose Luis Rodriguez Gonzalez
    ------------------------------


  • 2.  RE: Write table to file using tab as delimiter

    Posted Thu May 25, 2023 12:57 PM
    Hi José,
     
    Here is an example of how to transform a table into a TAB-delimited file.
     
    defVar --name tab --type String
    defVar --name fullText --type String
    defVar --name defaultPath --type String
    defVar --name dataTable --type DataTable
    setVar --name "${tab}" --value "\t"
    jsonToTable --handleError  --json "  {\n    \"person\": [\n      {\n        \"firstName\": \"John\",\n        \"lastName\": \"doe\",\n        \"age\": 26\n      },\n      {\n        \"firstName\": \"Smith\",\n        \"lastName\": \"zen\",\n        \"age\": 45\n      }\n    ]\n  }" --jsonPath "$.person" --comment "I used a json to create a sample table" dataTable=value
    setVar --name "${fullText}" --value "${dataTable}"
    trimString --text "${fullText}" --trimoption "TrimStartAndEnd" fullText=value
    replaceText --texttoparse "${fullText}" --textpattern "," --replacement "${tab}" fullText=value
    getSpecialFolder --folder "Desktop" defaultPath=value
    writeToFile --value "firstName${tab}lastName${tab}age\r\n${fullText}" --file "${defaultPath}\\person.txt" --encoding "Default" --overwrite

    I hope it helps you.
     
    Cheers.


    ------------------------------
    Angelo Alves
    IBM RPA Technical Specialist
    ------------------------------