Page 1 of 1

Find and replace batch file

Posted: 11 Aug 2010 01:22
by shekhar_kr
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

Re: Find and replace batch file

Posted: 11 Aug 2010 04:29
by !k

Re: Find and replace batch file

Posted: 15 Aug 2010 13:11
by SenHu
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")