I want to create a batch while which finds specific lines in a batch file and are able to edit these lines.
Example:
//TXT FILE//
ex1
ex2
ex3
ex4
i want to let the batch file find 'ex3' and edit this to 'ex5' to let it look like this:
ex1
ex2
ex5
ex4
You can do like this:
There is no search and replace function or stream editing at the command line in XP or 2k3 (dont know about vista or beyond). So, you'll need to use a script like the one Ghostdog posted, or a search and replace capable tool like sed.
There is more than one way to do it, as this script shows:
ghostdog74's example provided the core of what I needed, since I've never written any vbs before and needed to do that. It's not perfect, but I fleshed out the example into a full script in case anyone finds it useful.
If you are on Windows, you can use FART (Find And Replace Text). It is only 1 single *.exe file (no library needed).
All you need to is run:
This is the kind of stuff
sed
was made for (of course, you need sed on your system for that).sed 's/ex3/ex5/g' input.txt > output.txt
You will either need a Unix system or a Windows Cygwin kind of platform for this.
There is also GnuWin32 for sed. (GnuWin32 installation and usage).
You can always use "FAR" = "Find and Replace". It's written under java, so it works where Java works (pretty much everywhere). Works with directories and subdirectories, searches and replaces within files, also can renames them. Also can rename bulk files.Licence = free, for both individuals or comapnies. Very fast and maintained by the developer. Find it here: http://findandreplace.sourceforge.net/
Also you can use GrepWin. Works pretty much the same. You can find it here: http://tools.tortoisesvn.net/grepWin.html