If I understood correctly this will be enough:
if ($line -match "Transfered.*ROK=[^\*].*ZEN")
Question
I read a file and I search some specific lines that contains the word "transfered" and the CODES "ZEN" and "ROK".
My script should select only the lines with these three parameters BUT the ROK should not be a star character *
.
Here an example and the condition that I wrote:
lines:
Transfered TWIST=1 ROK=TOTO ZEN=C2813310
Transfered TEST2=3 ROK=* ZEN=C2813310
Transfered CALIB=7 ROK=* ZEN=C2813310
Transfered LIKR1=9 ROK=TOTO ZEN=C2813310
My if condition in order to match the elements:
$content = get-content "c:\test\log"
foreach ($line in $content) {
if ($line -match "Transfered.*ZEN=(.+?)\b.*")
My question is how to add to the same "if" condition the "ROK" parameters that it should not be equal to a *
star.
So, at the end of the script, from the example above, I should have only these two lines where ROK is not equal to *
:
Transfered TWIST=1 ROK=TOTO ZEN=C2813310
Transfered LIKR1=9 ROK=TOTO ZEN=C2813310
My script does also other tasks but these tasks are based no this filter that I have to apply.
Thank you in advance.
ps: I tried this one but didn't work:
if ($line -match "Transfered.*ZEN=(.+?).*ROK=(.+?)\b.*")
La solution
If I understood correctly this will be enough:
if ($line -match "Transfered.*ROK=[^\*].*ZEN")
Autres conseils
try this:
$data = @'
I read a file and I search some specific lines that contains the word "transfered" and the CODES "ZEN" and "ROK". My script should select only the lines with these three parameters BUT the ROK should not be a star character "*".
Here an example and the condition that I wrote:
lines:
Transfered TWIST=1 ROK=TOTO ZEN=C2813310
Transfered TEST2=3 ROK=* ZEN=C2813310
Transfered CALIB=7 ROK=* ZEN=C2813310
Transfered LIKR1=9 ROK=TOTO ZEN=C2813310
My if condition in order to match the elements:
'@.split("`n")
$data | ? { $_ -match 'Transfered.*ROK=[^*]+ZEN.*' } | % {$_}