December 28, 2020 at 6:55 pm #282802ParticipantTopics: 2Replies: 1Points: 14Rank: Member
I have a tab delimited .txt file that I’m simply loading into a variable but it’s like it’s not recognizing the tab and tossing everything in each row into the first column. The .txt file example is the following….
column1 column2 column3 column4 column5
1 2 3 4 5
2 5 4 6
4 4 6 4
4 5 6 4 6
And the PowerShell code is as follows….
$data = Import-Csv -Delimiter
t -Path C:\temp\testimport.txt<</strong>
<strong>$data | Format-Table</strong>
Any idea what the problem is? I thought t was the correct switch for tab delimiting. Thanks in advance for any help on the issue.
December 29, 2020 at 10:28 am #282982ParticipantTopics: 5Replies: 249Points: 985Rank: Major Contributor
It could be just the formatting on your post, but the data is single space delimited instead of tab delimited. Assuming the .txt file is actually tab delimited you need to specify the delimiter by escaping the literal “t” otherwise it is trying to look for a literal “t” character to delimit the data items. In PowerShell the backtick is the escape character. Here’s what it should look like.PowerShell1$data = Import-Csv -Delimiter "`t" -Path "C:\temp\testimport.txt"
- This reply was modified 2 weeks, 6 days ago by Mike R..
- You must be logged in to reply to this topic.