If you need to process a CSV file, you can use PowerShell's import-csv command. If headers exist in the first line of the CSV, then they will be used as property names on the resulting import-csv output. For example, if you CSV looks like:
Last,First,Middle
Jones,Fred,S
Smith,Sally,M
Johnson,Bob,L
Then you can output the full names like:
import-csv employees.csv |% `
{[string]::format("{0} {1} {2}",$_.first, $_.middle,$_.last)}
Or if you only want last names that start with a "J", you can:
import-csv employees.csv | `
where {$_.last.startswith("J")} |% `
{[string]::format("{0} {1} {2}",$_.first, $_.middle,$_.last)}
Pretty cool, eh?
PowerShell v2 will have the ability to change what the delimiting character is.
Just some random development ramblings mostly related to the Microsoft .NET platform.
Showing posts with label CSV. Show all posts
Showing posts with label CSV. Show all posts
Saturday, August 9, 2008
Subscribe to:
Posts (Atom)
Can't RDP? How to enable / disable virtual machine firewall for Azure VM
Oh no! I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore. I did ...
-
Don't want Office 2007 installed on your web server to access Excel 2007 content? Here is a Visual Studio C# solution that demonstrates ...
-
I finally found a good algorithm to validate a file path (had to fix two bugs in it though). I use this static method in Windows Forms when...