How can i select specific lines (and add. lines) from a CSV-File and write this “selection” to an array?
A specific line contains the string “Projekt:” and the selection ends up bevor next occurrence of the next string “Projekt:”, exepting last “selection”
Example CSV File:
16120007;VK;TKO;07.03.2016;20363;sho;17.03.2016;WE;;Projekt: ABC1;
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;121;35028061;RV 1;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;121;35028061;RV 2;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;121;35028061;RV 3;0
1;BN8;KF8;KWeiss; ;ob;1470;229;82;KF8;KF8;;;122;35028061;RV 4;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;127;35028061;RV 10;0
16120007;VU;TWO;07.03.2016;20363;sho;17.03.2016;WE;;Projekt: DEF2;
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;2121;35028062;RV 12;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;2121;35028062;RV 13;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;2127;35028062;RV 20;0
16120007;VO;SHE;07.03.2016;20363;sho;17.03.2016;WE;;Projekt: GHI3;
1;BN8-101-2xK;KF8;KWeiss; ;un;2140;200;82;KF8;KF8;;;3120;37009002;RV 21;0
1;BN8-101-2xK;KF8;KWeiss; ;un;1640;200;82;KF8;KF8;;;3121;37009002;RV 22;0
Array 1 shoud contain:
16120007;VK;TKO;07.03.2016;20363;sho;17.03.2016;WE;;Projekt: ABC1;
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;121;35028061;RV 1;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;121;35028061;RV 2;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;121;35028061;RV 3;0
1;BN8;KF8;KWeiss; ;ob;1470;229;82;KF8;KF8;;;122;35028061;RV 4;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;127;35028061;RV 10;0
Array 2 shoud contain:
16120007;VU;TWO;07.03.2016;20363;sho;17.03.2016;WE;;Projekt: DEF2;
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;2121;35028062;RV 12;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;2121;35028062;RV 13;0
1;BN8;KF8;KWeiss; ;ob;1980;229;82;KF8;KF8;;;2127;35028062;RV 20;0
Array 2 shoud contain:
16120007;VO;SHE;07.03.2016;20363;sho;17.03.2016;WE;;Projekt: GHI3;
1;BN8-101-2xK;KF8;KWeiss; ;un;2140;200;82;KF8;KF8;;;3120;37009002;RV 21;0
1;BN8-101-2xK;KF8;KWeiss; ;un;1640;200;82;KF8;KF8;;;3121;37009002;RV 22;0
Playing around a little bit with:
[regex]$Regex = “Projekt:”
(Get-Content C:\Avor\Kronenberger\Auftrag\CSV\community.txt | Measure-Object -Line).Lines
$TotalLines = (Get-Content C:\Avor\Kronenberger\Auftrag\CSV\community.txt | Measure-Object -Line).Lines
(Get-Content C:\Avor\Kronenberger\Auftrag\CSV\community.txt | Select-String -Pattern $Regex).count
Get-Content C:\Avor\Kronenberger\Auftrag\CSV\community.txt | Select-String -Pattern $Regex | Select-Object LineNumber
(Get-Content C:\Avor\Kronenberger\Auftrag\CSV\community.txt)[(0 + $NoProjectLineNumber1 -1)…(0 + $NoProjectLineNumber2 -2)]