+ Post New Thread
Results 1 to 13 of 13
Windows Thread, CLI find & replace. in Technical; I'm looking for a command line find and replace that will recursively search some file spec e.g. *.txt in some ...
  1. #1

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115

    CLI find & replace.

    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]

  2. #2


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,686
    Thank Post
    352
    Thanked 794 Times in 714 Posts
    Rep Power
    346
    sed or awk would be my recommendations.

    Can I ask if you know of them why they aren't suitable?

  3. #3

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115
    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]

  4. #4
    User3204's Avatar
    Join Date
    Aug 2006
    Location
    Wirral
    Posts
    769
    Thank Post
    55
    Thanked 66 Times in 62 Posts
    Rep Power
    34
    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

  5. #5

    Join Date
    Jan 2007
    Location
    Enfield, London
    Posts
    159
    Thank Post
    7
    Thanked 3 Times in 3 Posts
    Rep Power
    17
    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.
    Last edited by m2d2; 20th December 2008 at 08:07 PM.

  6. #6


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,686
    Thank Post
    352
    Thanked 794 Times in 714 Posts
    Rep Power
    346
    Wouldn't bother with cygwin, the gnu win32 binaries are sufficient.

  7. #7

    Join Date
    Jan 2007
    Location
    Enfield, London
    Posts
    159
    Thank Post
    7
    Thanked 3 Times in 3 Posts
    Rep Power
    17
    Quote Originally Posted by kmount View Post
    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.

  8. #8


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,686
    Thank Post
    352
    Thanked 794 Times in 714 Posts
    Rep Power
    346
    It has findutils which includes find, locate, etc.

  9. #9

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by User3204 View Post
    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

  10. #10

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115
    ::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?

  11. #11
    mossj's Avatar
    Join Date
    Dec 2008
    Location
    Leicester
    Posts
    1,466
    Thank Post
    157
    Thanked 189 Times in 174 Posts
    Rep Power
    52
    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.

  12. #12

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,512
    Thank Post
    1,320
    Thanked 469 Times in 306 Posts
    Blog Entries
    6
    Rep Power
    199
    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

  13. #13

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115
    ..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.

SHARE:
+ Post New Thread

Similar Threads

  1. How to find out which machine a student logged onto, & when
    By indiegirl in forum How do you do....it?
    Replies: 32
    Last Post: 16th March 2012, 01:17 PM
  2. CLI & GUI
    By Edu-IT in forum General Chat
    Replies: 7
    Last Post: 7th March 2008, 05:17 PM
  3. Time to replace?
    By cgiuk in forum Hardware
    Replies: 11
    Last Post: 24th January 2008, 08:27 AM
  4. A simple jabber cli message sender?
    By localzuk in forum Windows
    Replies: 2
    Last Post: 22nd May 2007, 12:55 PM
  5. cli consul program needed
    By edie209 in forum Wireless Networks
    Replies: 3
    Last Post: 26th July 2006, 05:38 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •