bookmark - Know Of Any Block Text Search & Replace Tools ( Across Multiple Files )

Know Of Any Block Text Search & Replace Tools ( Across Multiple Files )

 
 Discussion by miCRoSCoPiC^eaRthLinG with 11 Replies.
 Last Update: March 27, 2007, 4:17 pm
 
bookmark - Know Of Any Block Text Search & Replace Tools ( Across Multiple Files )  
    
free web hosting
 
The title says it all - am hunting for a freeware tool that'd allow me to search a BLOCK of text (as opposed to a line of text in most editors) across multiple files and replace it in all those files. Has anyone come across such a tool. I Googled and found a few paid ones and even gave a try to their trial versions - but all of them seemed buggy and ill-designed.

It'll be really great if someone can suggest such a tool.

Regards,
m^e

Mon Mar 26, 2007    Reply    New Discussion   


I haven't heard of such a program, but you could make it yourself. That way you would get exactly what you want and how you want it. I've even got an idea how to do it:

  1. Three text boxes: files, search and replace
  2. In each line of the first one would be a file you want to edit, the second one would contain what to search for, and the third what to replace it with
  3. When clicked on "Start", the program would load each line of the second and the third box in a array.
  4. After that, the program would load the file contents in an array (again, one element for each line)
  5. The program would then search the file array to see if any sequence of members matches the one in the search array - if it does, it would be replaced with the sequence in the replace array
  6. Finally, the file would be opened for writing and cleared, and then you'd write the new file array into it
  7. Repeat the process for all files

Might not be so fast, but will definitely do what you need.

Mon Mar 26, 2007    Reply    New Discussion   

I was on the job myself. It would be called Mr. Block Text ;).

Progress so far:-

> Add/Edit/Remove files to the list
> Search Forward + Backward in multiple files
> Replace / Replace All
> Backup Files before Replace

MrBlockText_WIP.jpg

Mon Mar 26, 2007    Reply    New Discussion   

Pyost, ;) I had the same thoughts too.. but who wants to go into the pain of writing one right now... lets see how turbo's software comes out..

Mon Mar 26, 2007    Reply    New Discussion   


Ok here goes the Work in Progress version.

http://ntek.astahost.com/wip/mrblocktext/

Hopefully, this would serve your purpose. Do mention the features you would like to be added/ripped off and any bugs that you encounter (I had to rush things 'cause of the classes). For now, the backups will be stored in the backup directory of the application with a timestamp prefix added to the filename.

Mon Mar 26, 2007    Reply    New Discussion   

Check it out and here are the problems:

Problems

  1. It finds and replaces ONLY the FIRST INSTANCE of a string in a file. The S & R function halts after that.
  2. After replacing a string, it pops-up a message-box saying "Replaced (x) Instances". That is fine - but it keeps reporting that it replaced an instance EVEN AFTER the replacing is over. What I mean is that supposing you've searched & replaced a particular string and there are no more instances of the same string in the file. If you the try S & R again, it still reports that 1 instance has been replaced ;)
  3. Back-up doesn't work yet
  4. The S & R function works on executables (.exes) too and dutifully screws them up even if there's NO POSSIBILITY of such a string occurring inside a .exe.

Suggestions:

  1. Include an option to add folders instead of single files.
  2. Include an option to recurse into subfolders and perform the S & R
  3. Add a file filter along with the above two - so you can specify say, *.txt or *.htm and it'll look for the string in only those file types.

Mon Mar 26, 2007    Reply    New Discussion   

If you don't need a gui program, awk will do this for you. The syntax can be a little confusing, but if you read the manpage you should have no problem devising an awk statement that will do anything you like.

Also, a perl script could do this extremely easily in less than 20 lines of code.

I forgot to mention, awk is both freeware AND open source.

Mon Mar 26, 2007    Reply    New Discussion   

ethergeek: If it was for myself - I'd probably use awk. Would have been a much faster and smoother approach. But this is for someone else, who sadly has no clue how to work out of the Windows box. So there... ;)

Mon Mar 26, 2007    Reply    New Discussion   

Well, I use CuteHTML for most of my editing needs and it includes a text replacement feature that I use a lot. It will search and replace text on the active document or all open documents.

It isn't very fancy and doen't use any regular expressions but with a little practice, you'll figure out how to overcome that.

It will do large blocks of text as well. The demo version stops providing code tips and more advanced features but the find and replace feature works great.

I use an older version - CuteHTML LE from 2001 ;)

You might give it a try, I'll look around and see if I still have the installer for it if you need.

vujsa

Mon Mar 26, 2007    Reply    New Discussion   

QUOTE (miCRoSCoPiC)

ethergeek: If it was for myself - I'd probably use awk. Would have been a much faster and smoother approach. But this is for someone else, who sadly has no clue how to work out of the Windows box. So there... ;)
Link: view Post: 100504


Roger that...though you still might be able to incorporate awk as the replacement backend for the text search/replace instead of writing your own regexes and routines. You can abstract the operation but still maintain the power of awk ;)

Mon Mar 26, 2007    Reply    New Discussion   

Ok I am on it.

QUOTE


It finds and replaces ONLY the FIRST INSTANCE of a string in a file. The S & R function halts after that.
Making the Find Next & Back work, was such a pain in the ass that I really didn't give enough thought to the replace all thingy.

QUOTE


After replacing a string, it pops-up a message-box saying "Replaced (x) Instances". That is fine - but it keeps reporting that it replaced an instance EVEN AFTER the replacing is over. What I mean is that supposing you've searched & replaced a particular string and there are no more instances of the same string in the file. If you the try S & R again, it still reports that 1 instance has been replaced


In the testings that I have been doing, it pops up with Replaced (0) Instances after a complete REPLACE ALL. I presume the replace text you are using creates another instance of the find text.
For Example:-

Find Text: Adam
Replace Text: Madam
Source Text: Adam ate the apple.
Final Text: Madam ate the apple.

It would be easier for me if you could attach the files you were testing on.

QUOTE


Back-up doesn't work yet
Backups are stored in a new directory 'Backup' which in turn is created in the folder the executable resides. Next release will have location customization feature.

QUOTE


The S & R function works on executables (.exes) too and dutifully screws them up even if there's NO POSSIBILITY of such a string occurring inside a .exe.


I'll include the filters to stop it from doing that.

Mon Mar 26, 2007    Reply    New Discussion   

The new tool, Search & Replace is ready.

Incorporated most of the features and hopefully bugs would be minimal.

You can get it from http://www.ntek.astahost.com/wip/searchandreplace/

Tue Mar 27, 2007    Reply    New Discussion   

Quickly Post to Know Of Any Block Text Search & Replace Tools ( Across Multiple Files )  w/o signup Share Info about Know Of Any Block Text Search & Replace Tools ( Across Multiple Files )  using Facebook, Twitter etc. email your friend about Know Of Any Block Text Search & Replace Tools ( Across Multiple Files ) Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Avg Free Vs Avast! Free   Avg Free Vs Avast! Free (38) (3) Portableapps: Your On-road Productivity Companion   Portableapps: Your On-road Productivity Companion