Reputation: 1
Hello fellow Stackoverflowers,
once again, I am stuck at a certain problem which I hope can be solved with PS:
A GIS program puts out lines in the following form into a csv:
"House 5";9660.7734;1782.7454;0;0;
"House 9";9675.0684;1779.7888;0;0;
"House 8";9675.0684;1779.7888;0;0;
"House 2";9688.3779;1777.323;0;0;
"House 12";9709.5742;1772.3938;0;0;
"House 11";9709.5742;1772.3938;0;0;
"House 12";9734.2217;1771.4075;0;0;
"House 8";9755.9111;1770.4211;0;0;
"House 5";9779.0801;1770.9155;0;0;
"House 7";9779.0801;1770.9155;0;0;
"House 2";9802.7412;1770.9155;0;0;
and so on....
I would like to keep that form but change each line's value after the 3rd semicolon (here 0) to values that are speficied by each line's 1st value (House XX). The values to be applied are 15 for House 5, 12 for House 8, 8 to House 2 and 3 to House 12.
Also, there are "Houses" in the list that dont have to be changed: House 9, House 11 and House 7.In the end , the output file (again csv) should look like this:
"House 5";9660.7734;1782.7454;15;0;
"House 9";9675.0684;1779.7888;0;0;
"House 8";9675.0684;1779.7888;12;0;
"House 2";9688.3779;1777.323;8;0;
"House 12";9709.5742;1772.3938;3;0;
"House 11";9709.5742;1772.3938;0;0;
"House 12";9734.2217;1771.4075;3;0;
"House 8";9755.9111;1770.4211;12;0;
"House 5";9779.0801;1770.9155;15;0;
"House 7";9779.0801;1770.9155;0;0;
"House 2";9802.7412;1770.9155;8;0;
So, when I provide the changevalues for all the different "Houses" (could also use a list), can a PS script save me the work of manual changing?
Thanks in advance!
Upvotes: 0
Views: 56
Reputation: 72610
So It's hollidays here, but I feel like doing sombody's homework :
Import-Csv yourfile.csv -Delimiter ';' -header 'a','b','c','d','e' | % {$a=$_;switch -regex ($_.a) {.*5 {$a.d=15} .*8 {$a.d=12} "House 12" {$a.d=3} "House 2" {$a.d=8}};$_}
You can pipe to export-csv.
Upvotes: 1