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
| $maj = "A-ZÀÁÂÈÉÊËÌÍÎÏÒÓÔÕÖØÙÚÛÜÇÑ"
$min = "a-zàáâãäåèéêëìíîïòóôõöøùúûüÿçñ"
$trimcar = ",", " ", "-"
$separator = ";"
$csvstr = "Fichier${separator}Nom${separator}Prenom${separator}Date décès${separator}Fils/fille${separator}Epoux/Epouse/Veuve/Veuf/Divorcé`n"
foreach ($file in (Get-Item -Path "*.txt")) #*.txt))
{
$nom = ""
$prenom = ""
$datedeces = ""
$filsoufillede = ""
$epouxépouseveuveveuf = ""
$content = Get-Content -Path $file
$content = $content -replace ' - ', '. '
$content = $content -replace '\s+', ' '
$nom = $content[0].Trim()
$content = $content -join ""
$contenttmp = $content.Substring($content.IndexOf($nom) + $nom.Length)
if ($contenttmp -cmatch "((\b[$maj]+\w*[\s,]+)*$nom)")
{
$prenom = $matches[0].Replace($nom, "").Trim($trimcar)
}
if ($content -match " (fille|fils|file)[^\.,]*")
{
$filsoufillede = $matches[0].Trim($trimcar)
}
if ($content -match "\s(Le.*)est décédé")
{
$datedeces = $matches[1].Trim($trimcar)
}
if ($content -match " (Fils de|Fille de)[^\.,]*")
{
$filsoufillede = $matches[0].Trim($trimcar)
}
if ($content -match "(Epoux de|epouse de|veuve de|veuf de|Divorcée de|Divorcé de)[^\.,]*")
{
$epouxépouseveuveveuf = $matches[0].Trim($trimcar)
}
$csvstr += $file.Name + ${separator} + $nom + ${separator} + $prenom + ${separator} + $datedeces + ${separator} + $filsoufillede + ${separator} + $epouxépouseveuveveuf + "`n"
}
Set-Content -Path "export.csv" -Force -Value $csvstr |
Partager