I am processing a csv file in powershell which looks like this:
<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
AUDJPY,20010102,230100,64.30,64.30,64.30,64.30,4
AUDJPY,20010102,230300,64.29,64.29,64.29,64.29,4
<snip>
I am using Import-Csv to process the file and I want to find return <DTYYYYYMMDD> values greater than 20110101. I tried this:
foreach($file in ls $PriceFolder\*.txt) {Import-Csv $file | Where-Object {$_.<DTYYYYMMDD> -ge 20110101}}
but I get this error
Missing property name after reference operator. I presume it’s because of the < symbol? How can I solve this?
1) Use {} to enclose not standard field names (or store them in a variable and refer as $_.$var);
2) Cast the value to [int] in order to avoid issues (data are read as strings from .csv; in this example this is not a problem perhaps but..)
This works: