How to use Power Shell to change TAB to ","

datatable
csv
powershell

#1

Good day everyone,

Today I come to you to ask for help. I am trying to read a CSV file that uses TAB as delimiter and convert it as data table. UiPath don’t recognize TAB as delimiter. I want to change the TAB for “,” using a power shell option.

Import-Csv -Delimiter `t | Export-Csv -NoTypeInformation

My problem is, -Delimiter only accept Char variable, and “`t” is not char.

Do anyone has faced a situation like this and wants to share ideas, or already solved somehow this problem?

I will continue investigating, and if I found something I will publish it.

Regards


#2

I don’t know enough about the powershell activity, but I found a way that works with other activities:

The Assign activity uses the expression csvText.Replace(ControlChars.Tab, ","). You can also install the Workflow Manager Activities package and find a special Replace String activity to do the same.


#3

Hey @anherrer

I have tried with text file contains with tab delimited earlier with this powershell command

so you can read your csv and convert it into text file by using Read text file activity like @sfranzen mentioned above.

(Get-Content “D:\Users\Desktop\sample.txt”) -replace “`t”, ", " | Set-Content “D:\Users\Desktop\sample.txt”

Regards…!!
Aksh


#4

Hello,

Thank you @sfranzen and @aksh1yadav for your answers.

From the time that I published till I saw your answers, I found this solution:

image

I created a PowerShell Script with UiPath.Core.Activities.WriteTextFile:

Import-Csv <filename.csv> -Delimiter `t | Export-Csv <newfilename.csv> -NoTypeInformation

And then running the script with the activity UiPath.Script.Activities.PowerShell.RunPowerShellScript.

Using the Invoke PowerShell option was complicated due to the fact that the delimiter “`t” is not valid for Char but could be more simple if the delimiter is just a character.

Hope this helps someone else later.

Regards.