This topic contains 3 replies, has 3 voices, and was last updated by
July 3, 2019 at 9:40 am #163848ParticipantTopics: 1Replies: 1Points: 15Rank: Member
I have a file containg (multiple) xml tags that contain the attribute type="ABC". The ABC needs to be replaced by XYZ.
I have tried to use the below (escape with backtick, as it seems to be the standard in powershell) and the variation of it by escaping the double quotes with the backslash (I'm basically a pure C programmer).
powershell -command "(gc %rootdir%\directory\file3.xml) -replace 'TYPE=`"ABC`"','TYPE=`"XYZ`"' | Out-File %rootdir%\directory\file.xml" -encoding ASCII
I eventually tried escaping the double quote with another double quote and that worked. The question is where I can read up on escaping in powershell or if somebody can explain why only the escaping the double quote with a double quote worked.
Thanks in advance
July 3, 2019 at 9:42 am #163854Senior ModeratorTopics: 8Replies: 1041Points: 3,439Rank: Community Hero
July 3, 2019 at 10:03 am #163857ParticipantTopics: 1Replies: 1529Points: 2,587Rank: Community Hero
You may read the free Powershell cookbook about working with XML files. I'd recommend to treat an XML file not like plain text. 😉
July 3, 2019 at 10:50 am #163863ParticipantTopics: 1Replies: 1Points: 15Rank: Member
Thanks people for the replies.
I'm aware that I will probably be better of using the XML approach but this is an attempt at a quick and dirty hack to fix a tool-chain after requirements for the output files changed.
You must be logged in to reply to this topic.