Jump to content

Recommended Posts

Posted

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]

Posted

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]

Posted (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 by m2d2
Posted
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.

  • 2 months later...
Posted
::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?
Posted
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.
Posted

..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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...