tags:

views:

68

answers:

1

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.....

Make sense...?

I have played with Get-Content | where-object and not had any luck....

UPDATE I was able to convert tabed file to csv.

Once I have the csv , 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

Any ideas to get it to sort by actual date ?

Preferably return only the dates from today + 30 days.

TIA.

+3  A: 

ConvertFrom-CSV has a -delimiter parameter. You should be able to specify tab. It returns objects, so you'd pipe it to "sort Date".

I'll have to look for how to specify a tab, though.

Found it..."`t"

So...try this:

convertfrom-csv .\test.csv -delimiter "`t" | sort-object MoveDate

Mike Shepard
Mike, Sweet, I am 90% there.It does not sort by date...the date field sorts by string so.1/12/20101/13/2010I need it sorted as a datetime field....My sample data looks like this in that field... 9/30/2009 12:21Any ideas to get it to sort by actual date ? (not string where 1 is first 2 2nd etc..)Preferably return only the dates from today + 30 days.
Harry
Give Sort-object a hint e.g. `... | Sort {[DateTime]$_.MoveDate}` Once Sort knows that it is sorting Dates instead of strings, it'll do a better job.
Keith Hill
Awesome. I haven't ever used that kind of thing with sort. I love learning new PowerShell goodies.
Mike Shepard
And for that last part...| where-object {[datetime]$_.MoveDate -lt (get-date).AddDays(30)}
Mike Shepard