Replace Strings based on the Line starting with a particular string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JessicaPearson
Posts: 3
Joined: 08 Mar 2022 07:13

Replace Strings based on the Line starting with a particular string

#1 Post by JessicaPearson » 08 Mar 2022 07:29

Hi All,
Please help to guide me on the below .

I am trying to replace a list of strings in a XML file, the strings are getting replaced but its getting replaced throughout the file, but I am trying to Findstr to replace strings only in the line which starts with <OfferName>, the file is very big and it will have multiple occurrences of <OfferName> tag, so I cannot use the exact line number.

Below is the part of the code which I am currently using , please let me know how can I Include only the lines which start with <OfferName>

Code: Select all

for /f "delims=: tokens=1*" %%a in ('findstr /n "^" "Offer_letter.XML"') do (
  set "line=%%b"
  call :ReplaceStrings

Thanks

JessicaPearson
Posts: 3
Joined: 08 Mar 2022 07:13

Re: Replace Strings based on the Line starting with a particular string

#2 Post by JessicaPearson » 08 Mar 2022 11:02

I was able to do a workaround on replacing the required strings but in the replaced file, this non-ascii charcter  is getting added automatically . I have searched on the internet and tried the below method but its not working.

Code: Select all

chcp 65001
ren Input.xml  Output.xml
Please help e on how to not generate this charcter  in the output file

JessicaPearson
Posts: 3
Joined: 08 Mar 2022 07:13

Re: Replace Strings based on the Line starting with a particular string

#3 Post by JessicaPearson » 08 Mar 2022 12:51

I was able to figure it out.

Thanks Guys

Post Reply