Jump to content
xisto Community
miCRoSCoPiC^eaRthLinG

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

Recommended Posts

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

Share this post


Link to post
Share on other sites

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:

Three text boxes: files, search and replace

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

When clicked on "Start", the program would load each line of the second and the third box in a array.

After that, the program would load the file contents in an array (again, one element for each line)

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

Finally, the file would be opened for writing and cleared, and then you'd write the new file array into it

Repeat the process for all files

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

Share this post


Link to post
Share on other sites

Ok here goes the Work in Progress version.

http://forums.xisto.com/no_longer_exists/

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.

Share this post


Link to post
Share on other sites

Check it out and here are the problems:

 

Problems

It finds and replaces ONLY the FIRST INSTANCE of a string in a file. The S & R function halts after that.

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 ;)

Back-up doesn't work yet

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:

Include an option to add folders instead of single files.

Include an option to recurse into subfolders and perform the S & R

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.

Share this post


Link to post
Share on other sites

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.

Edited by ethergeek (see edit history)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

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 ;)

Share this post


Link to post
Share on other sites

Ok I am on it.

 

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 *bottom* that I really didn't give enough thought to the replace all thingy.

 

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.

 

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.

 

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.

Share this post


Link to post
Share on other sites

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

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.