Flare Sci-fi Forums
Flare Sci-Fi Forums Post New Topic  New Poll  Post A Reply
my profile | directory login | search | faq | forum home

  next oldest topic   next newest topic
» Flare Sci-Fi Forums » Community » Officers' Lounge » Batch file find-and-replace (Page 1)

  This topic comprises 2 pages: 1  2   
Author Topic: Batch file find-and-replace
Saltah'na
Chinese Canadian, or 75% Commie Bastard.
Member # 33

 - posted      Profile for Saltah'na     Send New Private Message       Edit/Delete Post   Reply With Quote 
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
Lee
I'm a spy now. Spies are cool.
Member # 393

 - posted      Profile for Lee     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

--------------------
Never mind the Phlox - Here's the Phase Pistols

Registered: Jul 2000  |  IP: Logged
Omega
Some other beginning's end
Member # 91

 - posted      Profile for Omega     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

--------------------
"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      Profile for Cartman     Send New Private Message       Edit/Delete Post   Reply With Quote 
... 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      Profile for Saltah'na     Send New Private Message       Edit/Delete Post   Reply With Quote 
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
MinutiaeMan
Living the Geeky Dream
Member # 444

 - posted      Profile for MinutiaeMan     Send New Private Message       Edit/Delete Post   Reply With Quote 
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      Profile for Cartman     Send New Private Message       Edit/Delete Post   Reply With Quote 
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      Profile for Daniel Butler     Send New Private Message       Edit/Delete Post   Reply With Quote 
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
Mucus
Senior Member
Member # 24

 - posted      Profile for Mucus     Send New Private Message       Edit/Delete Post   Reply With Quote 
I like Perl, use it with Cygwin (a Linux-like environment for Windows).

Of course if you use Cygwin, you could use grep too.

Registered: Mar 1999  |  IP: Logged
Omega
Some other beginning's end
Member # 91

 - posted      Profile for Omega     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

--------------------
"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      Profile for Charles Capps     Send New Private Message       Edit/Delete Post   Reply With Quote 
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
MinutiaeMan
Living the Geeky Dream
Member # 444

 - posted      Profile for MinutiaeMan     Send New Private Message       Edit/Delete Post   Reply With Quote 
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
Mucus
Senior Member
Member # 24

 - posted      Profile for Mucus     Send New Private Message       Edit/Delete Post   Reply With Quote 
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      Profile for Cartman     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

Registered: Nov 1999  |  IP: Logged
Saltah'na
Chinese Canadian, or 75% Commie Bastard.
Member # 33

 - posted      Profile for Saltah'na     Send New Private Message       Edit/Delete Post   Reply With Quote 
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
  This topic comprises 2 pages: 1  2   

Quick Reply
Message:

HTML is enabled.
UBB Code™ is enabled.

Instant Graemlins
   


Post New Topic  New Poll  Post A Reply Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


© 1999-2024 Charles Capps

Powered by UBB.classic™ 6.7.3