Hi,
I have got one CSV file, which has 2 columns old_name and new_name. Then I have many XML files in which I want to find the old_name and replace with the new_name from the CSV file.
E.g. In CSV file I have data as follows in the same order:
old_name new_name
VENDR_TAB VRTB
VENDR_TAB_ADDR VRTBAR
Using this data I want to search old_name in XML file and replace with the new_name.
But the problem is since my first string is VENDR_TAB and its new name is VRTB, the moment it finds that string it replaces with new name. So VENDR_TAB_ADDR also becomes VRTB_ADDR, which is not what I want.
The script should search for the whole string and replace with the new ones. So the output for VENDR_TAB_ADDR should be VRTBAR and VENDR_TAB should be VRTB.
The script written by me is as follows:
$csv = Import-Csv D:\Temp\ast_dim.csv
$xmlfiles = Get-ChildItem D:\Temp\*.xml
foreach ($line in $csv)
{
foreach ($file in $xmlfiles)
{
#Write-Host $file
(gc $file) -replace $line.old_name, $line.new_name | Out-File $file -Encoding "ASCII"
}
}
Thanks In advance.