![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| | |||||||
| | Vista - CSV headers |
| |
| 12-14-2007 | #1 |
| | CSV headers There has to be an easy way to grab all the header names from a import-csv? ex: myfile.csv code,name,state,zip 34,mike,co,80525 68,jim,co,80528 and do $mydata= import-csv myfile.csv, how do I get out the names of the headers I'm tring to get the equivilant of $headNames= $("code",name","State","Zip") |
| My System Specs |
| 12-14-2007 | #2 |
| | Re: CSV headers Hi PSApple, Each header is represneted by a NoteProperty member, you can use get-member to list them: $csv = import-csv myfile.csv $headres = $csv | Get-Member -MemberType NoteProperty | foreach {$_.name} $headres ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic Quote: > There has to be an easy way to grab all the header names from a > import-csv? > > ex: myfile.csv > code,name,state,zip > 34,mike,co,80525 > 68,jim,co,80528 > and do $mydata= import-csv myfile.csv, how do I get out the names of > the > headers > I'm tring to get the equivilant of $headNames= > $("code",name","State","Zip") |
| My System Specs |
| 12-14-2007 | #3 |
| | Re: CSV headers Small typo: $headres -shouldBe $headers ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic Quote: > Hi PSApple, > > Each header is represneted by a NoteProperty member, you can use > get-member to list them: > > $csv = import-csv myfile.csv > $headres = $csv | Get-Member -MemberType NoteProperty | foreach > {$_.name} > $headres > ----- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic Quote: >> There has to be an easy way to grab all the header names from a >> import-csv? >> >> ex: myfile.csv >> code,name,state,zip >> 34,mike,co,80525 >> 68,jim,co,80528 >> and do $mydata= import-csv myfile.csv, how do I get out the names of >> the >> headers >> I'm tring to get the equivilant of $headNames= >> $("code",name","State","Zip") |
| My System Specs |
| 12-14-2007 | #4 |
| | Re: CSV headers You could use something like this. Import-Csv C:\Data\Scripts\testme.txt | get-member -type properties | foreach-object{$_.name} When you use import-csv it creates and object using the CSV headers as the properties and the values are attained from the csv. "PSApple" <mapplebee@xxxxxx> wrote in message news:u$PESVlPIHA.748@xxxxxx Quote: > There has to be an easy way to grab all the header names from a > import-csv? > > ex: myfile.csv > code,name,state,zip > 34,mike,co,80525 > 68,jim,co,80528 > > and do $mydata= import-csv myfile.csv, how do I get out the names of the > headers > I'm tring to get the equivilant of $headNames= > $("code",name","State","Zip") > > > > |
| My System Specs |
| 12-14-2007 | #5 |
| | RE: CSV headers try this: $mydata= import-csv myfile.csv $mydata | gm | Where-Object { $_.memberType -eq "NoteProperty" } | Select-Object name when you import-csv, PS will add the fields as member of array $mydata and they will be of "NoteProperty" type. -- Umesh "Old programmers never die. They just terminate and stay resident." "PSApple" wrote: Quote: > There has to be an easy way to grab all the header names from a import-csv? > > ex: myfile.csv > code,name,state,zip > 34,mike,co,80525 > 68,jim,co,80528 > > and do $mydata= import-csv myfile.csv, how do I get out the names of the > headers > I'm tring to get the equivilant of $headNames= $("code",name","State","Zip") > > > > > |
| My System Specs |
| 12-14-2007 | #6 |
| | Re: CSV headers $headNames = (gc myfile.csv -t 1).split(',') -replace '^\s' -- Kiron |
| My System Specs |
![]() |
| Thread Tools | |
| |
| Similar Threads for: CSV headers | ||||
| Thread | Forum | |||
| Headers in WLM | Live Mail | |||
| How to see headers | Live Mail | |||
| Headers Only | Live Mail | |||
| headers... | Vista mail | |||
| Headers | Vista mail | |||