Reputation: 78
I'm new to Powershell and need help in extracting table data that is there in a plain text file.
The plain text file data is in the below format.(Tab Separated)
Header1 Header2 Header3
Val1 Val2 Val3
Now, I want to extract this data and populate the variables like below.
$Header1 = "Val1"
$Header2 = "Val2"
$Header3 = "Val3"
Please help me with the right approach.
Upvotes: 1
Views: 688
Reputation: 2596
Basically you need to import-csv
and use the -delimeter
parameter and specify a tab as shown below
PS C:\Temp> $g = import-csv textfilewithtabs.txt -Delimiter "`t"
PS C:\Temp> $g
header1 header2 header3
------- ------- -------
value1 value2 value3
PS C:\Temp> $g | select header2
header2
-------
value2
PS C:\Temp> $g.header1
value1
PS C:\Temp> $g.header2
value2
Upvotes: 4