1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<#
Les éléments à supprimer:
- "BOESNER" le champs n°2 sera toujours égale à BOESNER
- "|0|0" le champs n°6 et 7 sera toujours égale aux même chiffres (mais je voudrais aussi supprimer les deux délimiteurs en plus "|0|0" )
- "1224|" le champs n°10 c'est l'heure en format numérique donc elle sera toujours composé de 4 chiffres mais différentes à chaque fois. il faut supprimer le délimiteur "1224|"
Le format de la date sera toujours -05- ou -03- jamais -3- ou -5-
Avant :
14|BOESNER|BORDEAUX|1|IN|0|0|COMPTAGE|03/13/2018 12:24:31|1224|1|0|140|8|192.168.100.100
Après :
14|BORDEAUX|IN|COMPTAGE|03/13/2018 12:24:31|1|0|140|8|192.168.100.100
#>
#fichier de test
$File='C:\Temp\Datas.dat'
@"
14|BOESNER|BORDEAUX|1|IN|0|0|COMPTAGE|03/13/2018 12:24:31|0111|1|0|140|8|192.168.100.100
14|BOESNER|BORDEAUX|1|IN|0|0|COMPTAGE|03/13/2018 12:24:31|1224|1|0|140|8|192.168.100.100
14|BOESNER|BORDEAUX|1|IN|0|0|COMPTAGE|03/13/2018 12:25:30|1225|1|0|141|8|192.168.100.100
14|BOESNER|BORDEAUX|1|IN|0|0|COMPTAGE|03/13/2018 13:50:31|1350|10|0|151|8|192.168.100.100
14|BOESNER|BORDEAUX|1|IN|0|0|COMPTAGE|03/13/2018 13:56:30|1356|11|0|152|8|192.168.100.100
14|BOESNER|BORDEAUX|1|IN|0|0|COMPTAGE|03/13/2018 12:24:31|2222|1|0|140|8|192.168.100.100
"@ > $File
[string[]]$Headers =1..15|%{"P$_"}
$Objects= Get-Content $File-
Convertfrom-Csv -Delimiter '|' -Header $Headers
$result=foreach ($Current in $Objects)
{
if ( ($Current.P2 -eq 'BOESNER') -and ($Current.P6 -eq '0') -and ($Current.P7 -eq '0'))
{
#supprime les champs 6,7 et 10
$TabOfString=Select-Object -InputObject $Current -Property P1,P2,P3,P4,P5,P8,P9,P11,P12,P13,P14,P15 |
ConvertTo-Csv -Delimiter '|' -NoTypeInformation
#reformate la seconde ligne et l'émet dans le pipeline
$TabOfString[1].Replace('"','')
}
}
$result
# 14|BOESNER|BORDEAUX|1|IN|COMPTAGE|03/13/2018 12:24:31|1|0|140|8|192.168.100.100
# 14|BOESNER|BORDEAUX|1|IN|COMPTAGE|03/13/2018 12:24:31|1|0|140|8|192.168.100.100
# 14|BOESNER|BORDEAUX|1|IN|COMPTAGE|03/13/2018 12:25:30|1|0|141|8|192.168.100.100
# 14|BOESNER|BORDEAUX|1|IN|COMPTAGE|03/13/2018 13:50:31|10|0|151|8|192.168.100.100
# 14|BOESNER|BORDEAUX|1|IN|COMPTAGE|03/13/2018 13:56:30|11|0|152|8|192.168.100.100
# 14|BOESNER|BORDEAUX|1|IN|COMPTAGE|03/13/2018 12:24:31|1|0|140|8|192.168.100.1 |
Partager