New Reply

Reading Pipe Delimited Files in Powershell

 
Share Thread Thread Tools
Jun23-12, 06:36 PM   #1
MLP
 

Reading Pipe Delimited Files in Powershell


Hello,
I am trying to learn Powershell and for my first exercise I started reading a file that we use at work. The file is pipe delimited and contains a header row. The field names contain underscores. Here is the header row (wrapped to fit this window).

H|Seq_Nbr|Data_Key |Plan_Type |Mod_Type |Plan_Name |Mod_Name |Plan_Desc |Mbr_T |Mbr_A |Mbr_B |Mbr_C |Mbr_D

The values of Data_Key are dot delimited. A typical value would be like "Planned.PlanMast.BU29" the rest of the values are strings without any punctuation marks. The last two fields are allowed to be empty.

To read the file in I've used the Powershell import-csv cmdlet like this:

file$ = import-csv c:\imp\ssw\admin\tbl_list_planned.tbl -Delimiter '|'

So far so good. Next I want to return three fields according to whether or not one of the fields meets a certain criteria. Breaking this in parts, I sought first just to get the three fields I require. The next two lines seem to do the trick:

$fields = $file[0].psobject.properties | %{$_.name}
$file | select $fields[2,4,5]

So now I know how to get just the three fields I want. The last step is to pare this result down to just those records where field 4 (mod_type) is some value I care about. I've had no success doing this going down the road we're on. I've tried:

$rows = $file | select $fields[2,4,5]| where {$_ -like "BUPP29"}

I've tried:

$file = import-csv c:\imp\ssw\admin\tbl_list_planned.tbl -Delimiter '|' | where-object {$_.mod_type -eq "BUPP29"}

I tried:

import-csv C:\imp\ssw\admin\tbl_list_Planned.tbl -Delimiter "|" | % { foreach ($s in $_) { $s.split.("|")[4] } }

I'm floundering around and haven't found anything on the web. Thanks in advance to anyone who can give me a pointer.
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Bird's playlist could signal mental strengths and weaknesses
>> Minus environment, patterns still emerge: Computational study tracks E. coli cells' regulatory mechanisms
>> Bacterium uses natural 'thermometer' to trigger diarrheal disease, scientists find
New Reply
Thread Tools


Similar Threads for: Reading Pipe Delimited Files in Powershell
Thread Forum Replies
Reading .txt files to an array in C language Programming & Comp Sci 11
FORTRAN95 dealing with space delimited data files Programming & Comp Sci 4
matlab :: problen with reading from files - need help Programming & Comp Sci 4
Yet another c++ question - reading multiple files Computing & Technology 5