This topic contains 5 replies, has 2 voices, and was last updated by
February 13, 2017 at 6:30 pm #64114
I have 5 *.xml files in a directory. Within each file, there is a line: Content-ID:
The literal content id data is 3-4 delimited pieces. I need to replace the 1st **** with $date ( $date = Get-Date -format "yyyyMMdd" )
Your suggestions are greatly appreciated. Thank you!
February 13, 2017 at 6:38 pm #64117
Show your code.
February 13, 2017 at 7:08 pm #64120
On a high level you could do something like this:
Read all xml files you want to modify and store this list in a variable. Create a foreach loop over this variable. Inside this loop read the xml nodes of the file, select the node you want to change and use the -replace operator with a sofisticated regex pattern. Then you just have to save the changed xml data either to the original file or to a new one.
February 14, 2017 at 10:47 pm #64201
Thank you so much, Olaf. Here's my biggest struggle: I don't know what the text is that's needing to be replaced.
This is a line in the xml files where I need to replace sbteev510b2bsbt. "sbteev510b2bsbt" will be different every time.
What if you don't know what you are replacing but know where it is: I know the line begins with Content-ID and I want to replace sbteev510b2bsbt
I have been scouring and reading but not finding the answer. Thank you!
February 14, 2017 at 11:02 pm #64204
😉 That's the moment where the sophisticated regex pattern appears on the stage ....
$date = Get-Date -format "yyyyMMdd" 'Content-ID: sbteev510b2bsbt-rn20-preamble' -replace '(?< =Content-ID:\s+).+?(?=-rn20-preamble)',$date
You just need to know the "structure" of the ID or the possible format. If it's always something between a white space and a "minus" ... it will fit.
February 14, 2017 at 11:18 pm #64207
Wow; you made that SO EASY!!!! Thank you for teaching!
The topic ‘Data Replacement Method Needed’ is closed to new replies.