Saltah'na
Chinese Canadian, or 75% Commie Bastard.
Member # 33
posted
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.
-------------------- "And slowly, you come to realize, it's all as it should be, you can only do so much. If you're game enough, you could place your trust in me. For the love of life, there's a tradeoff, we could lose it all but we'll go down fighting...." - David Sylvian FreeSpace 2, the greatest space sim of all time, now remastered!
Registered: Mar 1999
| IP: Logged
posted
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
Regular expressions sound like the ticket for you. That or Python. But you should learn both no matter what, because they're cool. Unless, for some reason, it absolutely needs to be a DOS batch file.
-------------------- "This is why you people think I'm so unknowable. You don't listen!" - God, "God, the Devil and Bob"
Registered: Mar 1999
| IP: Logged
Cartman
just made by the Presbyterian Church
Member # 256
posted
... 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)
-------------------- ".mirrorS arE morE fuN thaN televisioN" - TEH PNIK FLAMIGNO
Registered: Nov 1999
| IP: Logged
Saltah'na
Chinese Canadian, or 75% Commie Bastard.
Member # 33
posted
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.
-------------------- "And slowly, you come to realize, it's all as it should be, you can only do so much. If you're game enough, you could place your trust in me. For the love of life, there's a tradeoff, we could lose it all but we'll go down fighting...." - David Sylvian FreeSpace 2, the greatest space sim of all time, now remastered!
Registered: Mar 1999
| IP: Logged
posted
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.)
-------------------- “Those people who think they know everything are a great annoyance to those of us who do.” — Isaac Asimov Star Trek Minutiae | Memory Alpha
Registered: Nov 2000
| IP: Logged
Cartman
just made by the Presbyterian Church
Member # 256
posted
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.
Registered: Nov 1999
| IP: Logged
Daniel Butler
I'm a Singapore where is my boat
Member # 1689
posted
Perl will run on winshite. But you'll die of internal hemhorraging figuring out it's syntax. Happens to everyone.
Registered: Jul 2005
| IP: Logged
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.
-------------------- "This is why you people think I'm so unknowable. You don't listen!" - God, "God, the Devil and Bob"
Registered: Mar 1999
| IP: Logged
Charles Capps
We appreciate your concern. It is noted and stupid.
Member # 9
posted
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.
Registered: Mar 1999
| IP: Logged
posted
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.
-------------------- “Those people who think they know everything are a great annoyance to those of us who do.” — Isaac Asimov Star Trek Minutiae | Memory Alpha
Registered: Nov 2000
| IP: Logged
posted
Perl is big in bioinformatics, although I technically learned it working on a language (machine) translation program.
Registered: Mar 1999
| IP: Logged
Cartman
just made by the Presbyterian Church
Member # 256
posted
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.)
Saltah'na
Chinese Canadian, or 75% Commie Bastard.
Member # 33
posted
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.....
-------------------- "And slowly, you come to realize, it's all as it should be, you can only do so much. If you're game enough, you could place your trust in me. For the love of life, there's a tradeoff, we could lose it all but we'll go down fighting...." - David Sylvian FreeSpace 2, the greatest space sim of all time, now remastered!
Registered: Mar 1999
| IP: Logged