Find and replace batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
shekhar_kr
Posts: 1
Joined: 11 Aug 2010 01:15

Find and replace batch file

#1 Post by shekhar_kr » 11 Aug 2010 01:22

Hello every one,
I am veryu new to batch programming. I have a requirement where i need to find a string in an text file and then replace it with my value. the string is something like
<propname name="Group.duration></propname>
now i want to search this particilar string and replace it with
<propname name="Group.duration>30</propname>


please help me as I dont know how to proceed
regards,
Shekhar


SenHu
Posts: 19
Joined: 19 Mar 2009 14:57

Re: Find and replace batch file

#3 Post by SenHu » 15 Aug 2010 13:11

Here is one possible script. I have assumed that your input file is at C:/xyz.xml.

Code: Select all

# Script FAR.txt
var str content, value
cat "C:/xyz.xml" > $content
sal -r -c "^<propname name=\"Group.duration\>&</propname\>^" ("^<propname name=\"Group.duration\>"+$value+"</propname\>^") $content > null
echo $content > "C:/xyz.xml"


Save the script in file C:/Scripts/FAR.txt. Script is in biterscripting. Start the script, and run this command.

Code: Select all

script "C:/Scripts/FAR.txt" value("30")



The value() ("30" in this case) will be placed between two marker tags in file C:/xyz.xml. To run this automatically periodically, just schedule this command with cron or scheduler.

Code: Select all

"C:/biterscripting/biterscripting.exe" "C:/Scripts/FAR.txt" value("30")

Post Reply