I have 1 folder filled with .DAT files.
I need to find all lines that look like this: NM1PR2AARP MEDICARE COMPLETE*****PI87726~
And replace the last field with the value from a database lookup from field 4 like this:
NM1PR2AARP MEDICARE COMPLETE*****PImap1stString ~
I have no idea how to this the smart way so this is what I am doing:
- Combine all the files.
Get-Content C:\test2\QTR2WHCfull\QTR2WHC*.DAT | Out-File C:\test2\Combined.DAT
- Find all the strings I need to replace.
get-content “C:\test2\Combined.DAT” | Select-String -Pattern ‘NM1*PR’ -simplematch | sort | Get-Unique | Set-Content “NM1lines.txt” # there are about 300
- Then I loop through each file and do a replace looking for one of those 300 lines.
$configFiles = Get-ChildItem -path "C:\test2\" *.DAT
foreach ($file in $configFiles)
{
(Get-Content $file.PSPath) |
Foreach-Object { $_ -replace " NM1\*PR\*2\*AARP HEALTHCARE OPTIONS\*\*\*\*\*PI\*36273", " NM1*PR*2*AARP HEALTHCARE OPTIONS*****PI*map1stString" `
-replace " NM1\*PR\*2\*AARP MED SUPP\*\*\*\*\*PI\*36273", " NM1*PR*2*AARP MED SUPP*****PI*map2ndString" `
#298 more possible replacements } |
set-Content $file.PSPath
This is the SQL I would use if I knew how to pull field 4 from the string and replace field 10
Select MappedValue FROM [837WHCinsuranceDictionary] WHERE [Name]= ‘AARP HEALTHCARE OPTIONS’
-Thanks,
Kevin