Tab delimited file not displaying correctly as table

Welcome Forums General PowerShell Q&A Tab delimited file not displaying correctly as table

Viewing 1 reply thread
  • Author
    Posts
    • #282802
      Participant
      Topics: 2
      Replies: 1
      Points: 14
      Rank: 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&lt</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.

      • This topic was modified 3 weeks ago by bjones1086.
      • This topic was modified 3 weeks ago by bjones1086.
      • This topic was modified 3 weeks ago by bjones1086.
      • This topic was modified 3 weeks ago by bjones1086.
    • #282982
      Participant
      Topics: 5
      Replies: 249
      Points: 985
      Helping Hand
      Rank: 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.

       

      • This reply was modified 2 weeks, 6 days ago by Mike R..
Viewing 1 reply thread
  • You must be logged in to reply to this topic.