Quick way to read a tab-delimited file and sort by date column using PowerShell
What is the best/quickest way to read a tab-delimited file and process only a few columns?
Sample:
Name\tAddress\tCit\t\State\Zip\Date of Move
I am looking to only get column1 and colum6 for the next 30 days (Name, Date of Move and sort by Date of Move's scheduled in the next 30 days...).
I have played with Get-Content | Where-Object and have not had any luck...
UPDATE
I was able to convert a tabbed file to CSV.
Once I开发者_如何学Go have the CSV file, I have done the following to get only the columns I need.
PS D:> import-csv .\test.csv | Select "Name", " MoveDate", "Address" | Sort-Object "MoveDate"
This returns the columns I need only, but does not sort by date...the date field sorts by string so.
1/12/2010 1/13/2010
I need it sorted as a datetime field...
My sample data looks like this in that field...
9/30/2009 12:21
How do I get it to sort by actual date?
Preferably return only the dates from today + 30 days.
ConvertFrom-Csv has a -Delimiter parameter. You should be able to specify tab. It returns objects, so you'd pipe it to "sort Date".
A tab is specified by "`t". So try this:
ConvertFrom-Csv .\test.csv -Delimiter "`t" | Sort-Object MoveDate
精彩评论