This is topic Batch file find-and-replace in forum Officers' Lounge at Flare Sci-Fi Forums.


To visit this topic, use this URL:
https://flare.solareclipse.net/ultimatebb.php/topic/10/3984.html

Posted by Saltah'na (Member # 33) on :
 
I need to make a batch file to find one set of strings and replace it with another set of strings.

Does anyone know the proper command that can be used for this?

Thanks.
 
Posted by Lee (Member # 393) on :
 
I just used to input data into Word or WordPad, or convert it to something readable in Excel, and do a straight Find'n'Replace from the menu option. That's in the case of data in a file. For batch renaming of files, I'd get a file listing (using dir /b >filename.txt), paste it into an Excel column, paste the new filename(s) into another column, and stick "REN" in front, then export it to a Text file, clean that up, and save it as a .bat file. And run it.

Not sure if that's any help, because I'm not sure what it is you want to do.
 
Posted by Omega (Member # 91) on :
 
Regular expressions sound like the ticket for you. That or Python. But you should learn both no matter what, because they're cool. [Smile] Unless, for some reason, it absolutely needs to be a DOS batch file.
 
Posted by Cartman (Member # 256) on :
 
... In which case you should still get Python, make gratuitous use of the re module, and then convince whoever wants this done to drop batch-files on the spot. B)
 
Posted by Saltah'na (Member # 33) on :
 
This is for a development project that I need to do. So yeah, can't simply just "open" some app and do a find and replace. It has to be automatic.

This is part of a batch file that I will be using to install scripts, but the scripts need to have a certain "parameter" to be filled in, hence the find-and-replace idea.

Help would be appreciated.
 
Posted by MinutiaeMan (Member # 444) on :
 
I agree that regular expressions (regex) are probably the best option. If this is for an automated script, grep would probably be the best bet. I use it quite often when updating and modifying the code for my website. (Like the time I decided to ditch all the <cite> tags I'd been using improperly, and replacing them with regular italics.)
 
Posted by Cartman (Member # 256) on :
 
Running grep on an MS platform would be difficult.

You could learn the monstrosity that is VBScript, and implement a regex F&R operation in that.
 
Posted by Daniel Butler (Member # 1689) on :
 
Perl will run on winshite. But you'll die of internal hemhorraging figuring out it's syntax. Happens to everyone.
 
Posted by Mucus (Member # 24) on :
 
I like Perl, use it with Cygwin (a Linux-like environment for Windows).

Of course if you use Cygwin, you could use grep too.
 
Posted by Omega (Member # 91) on :
 
Perl has a syntax?

Can you describe this development project? Because in most cases I'm envisioning, any language with good string support (i.e. anything from the last fifteen years) should be able to do what you want fairly automatically. And thus you should use Python, since it's superior to any other language by orders of magnitude. Ruby can bite my shiny metal ass.
 
Posted by Charles Capps (Member # 9) on :
 
Since when did half of the people that just posted in this topic even know what the fuck a regex was?

I will recommend Perl, not just because I'm biased, but because it's superior to Python. Any modern language that does regexes does them Perl-style anyway. Even Java. There's even an external compat library just for that purpose.

Let the religious wars begin.
 
Posted by MinutiaeMan (Member # 444) on :
 
I started learning a bit of regex when I adopted BBEdit as my primary web coding app. It includes grep search with regex. I don't use it all the time, but it's come in handy on numerous occasions.
 
Posted by Mucus (Member # 24) on :
 
Perl is big in bioinformatics, although I technically learned it working on a language (machine) translation program.
 
Posted by Cartman (Member # 256) on :
 
Whereas regexes themselves are pretty ubiquitous in CS/AI (automata- and formal language theory, compiler construction, computational linguistics, etc), so try to contain your amazement, chief.

(On that note, you haven't lived until you've built your own pattern matcher in Lisp.)

Also, this is quite possibly the best argument against Perl ever.
 
Posted by Saltah'na (Member # 33) on :
 
Perl? Python? For this batch file to work it has to work without any bells and whistles. Just plain command prompt on Windows. This is supposed to be a batch file that is supposed to run on ANY system, no need for visual basic to be installed or anything like that.....
 
Posted by MinutiaeMan (Member # 444) on :
 
quote:
Originally posted by Saltah'na:
Just plain command prompt on Windows. This is supposed to be a batch file that is supposed to run on ANY system[...]

I detect an inherent contradiction in that statement... [Wink]
 
Posted by Omega (Member # 91) on :
 
So you need a command line application that does find and replace. You really do need grep. [Smile] Perhaps findstr will do?
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/findstr.mspx?mfr=true

Failing that, you can write a Python script and compile to to an executable.
 


© 1999-2024 Charles Capps

Powered by UBB.classic™ 6.7.3