PiqueABoo Posted December 17, 2008 Posted December 17, 2008 I'm looking for a command line find and replace that will recursively search some file spec e.g. *.txt in some folder and replace "some text" with "some other text". So far I've found replace.exe 1.1 (bestcode.com) which may well do the trick. Anyone used and fond of anything else for this? [Have previously used and know about win32 ports of nix utils like sed]
kmount Posted December 17, 2008 Posted December 17, 2008 sed or awk would be my recommendations. Can I ask if you know of them why they aren't suitable?
PiqueABoo Posted December 17, 2008 Author Posted December 17, 2008 Yup.. because it's been maybe year since I did something for real with those utils, which as lots of irksome folk used to say is about 10 years at "web-speed", and what I knew then has been displaced by the million things I've had to know since. [Or: I've forgotten the syntax and I vaguely recall it was non-trivial]
User3204 Posted December 18, 2008 Posted December 18, 2008 I like Windows Grep Search Utility Home Page I know you wanted command line.. but there's also Grep for Windows or Grep for Windows
m2d2 Posted December 20, 2008 Posted December 20, 2008 (edited) To do things programatically I would probably install cygwin then use a mixture of find and sed If you want to use only Microsoft tools then you could probably a mixure of FOR /R to crawl the folder tree and a VB script for the find a replace. I suppose you could also Word as an IDE/runtime and knockup a quick app in VBA. It's the tree crawling that would be the tricky bit. Edited December 20, 2008 by m2d2
kmount Posted December 20, 2008 Posted December 20, 2008 Wouldn't bother with cygwin, the gnu win32 binaries are sufficient.
m2d2 Posted December 20, 2008 Posted December 20, 2008 Wouldn't bother with cygwin, the gnu win32 binaries are sufficient. Yeah but I don't remember if gnu tools binaries had a find equivalent.
kmount Posted December 20, 2008 Posted December 20, 2008 It has findutils which includes find, locate, etc.
mac_shinobi Posted December 20, 2008 Posted December 20, 2008 I like Windows Grep Search Utility Home Page I know you wanted command line.. but there's also Grep for Windows or Grep for Windows Quick google and I found this : FART: Find And Replace Text Not sure if thats of any use
PiqueABoo Posted February 22, 2009 Author Posted February 22, 2009 ::sob:: Have been getting along fine with this, but now *some* of the files I want to fiddle with in a recursive trawl through some folders are UTF-16 (unicode). Don't suppose anyone has ever seen the kind of util described at the start of the thread that also automagically handles that?
mossj Posted February 23, 2009 Posted February 23, 2009 I know you said cmd line, but you could set the folder as a dreamweaver local site and use find & replace on it all.... I think it should work.
RabbieBurns Posted February 23, 2009 Posted February 23, 2009 Ive been using a lot of python scripts of late, and know they can handle unicode. Search and replace text in a file. « ActiveState Code maybe someone would be able to modify one of them that works with unicode
PiqueABoo Posted February 23, 2009 Author Posted February 23, 2009 ..then it dawned on me that I'd already spent more time looking for this util than it would take to write, and it only took a couple of dozen significant lines of C# to make one Good-Enough-For-Me[tm]. The only real trick was not taking UTF8 (the encoding reported for ye olde text files) at face value, because it says that about binary files too. Not that I'm expecting to meet lots of .EXEs renamed to .TXT, but you never know - so for now I just scan through UTF8 files and if I hit a 0x00 decide it's not text. Will make it more bomb-proof sometime and post it.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now