I am working on a script that collects a lot of lines of data. The main thing bugging me is I want the Name
to be copied after a string until it hits the next Name
item and from then use that name to the next strings. I will turn this text file into a CSV and the rest of my script takes over from that. But I cannot do that until I can correctly comma deliniate this. The format I want is:
X,Y,Name
Lat,Lon,Red1
Lat,Lon,Red1
Lat,Lon,Red2
Lat,Lon,Red3
...
Currently I have my source text organized as:
Red1
Lat,Lon
Lat,Lon
Red2
Lat,Lon
Red3
Lat,Lon
...
Due to my source text will change and usually involves more than 500 lines, I do not want to simply copy and paste it in CSV format, that is making me prompt the user to make the changes and then hit yes to proceed, I wish to make the script a click once and out comes the result.
I have tried to use something like this:
(Get-Content $Makron2\kmlPrep1.txt -Raw) -replace '<kml:name>(.*?)</kml:name>', '<kml:name>,,NameStart,$1</kml:name>' |Set-Variable -Name "NameX" -Value '$1' |Set-Content -path $Makron2\kmlPrep1.txt
I want what is in between the <kml:name> </kml:name>
, save it as a variable, and then paste it after Lat,Lon,$NameX
(Get-Content $Makron2\kmlPrep2.txt) -replace '<kml:coordinates>','$NameX' | Set-Content -Path $Makron2\kmlChangeMe.txt
In the previous I have it replacing as well for another purpose, but I am wondering if its possible to save what is in the (.*?)
and then recall it later rather just in this statement. the previous only returns $1
instead of Red1
or any other names.
But it's not working for me, as I am limited in how to grep things in PowerShell. I am mostly self taught in this.