Alex Rivera | Logout

Multi line search and replace tool

Asked 2008-11-06T09:23:50.863
23

I am looking for a tool to replace multiple lines through out a project. For example:

#include "../DiscreteIO/Discrete.h"
#include "../PCI/pci.h"
#include "../Arinc429/ARINC429.h"

with

#include "../PCI/pci.h"
#include "../DiscreteIO/DiscreteHW.h"
#include "../DiscreteIO/Discrete.h"

I have tried two tools that work for this type of search and replace. Wildedit and Actual search and replace Both seem to be excellent tools but are shareware. Do anybody know of similar tools? Anything free or is it time to part with some money?

Clarification:

through out a project in this case means a thousand plus c files. The text editors can do this only one file at a time (Textpad, Programmers notepad) or in all open files(nodepad++). I haven't tried any of the other editors but I assume they will have similar problems. Please correct me if I am wrong.

Tools like sed & awk is a solution but present problems since I do not use them regularly and need to spend some time getting something to work since I am not a expert on the tools.

The answer is: All of it...

Ultra edit can work but I already have an editor and the price is steep if I am just going to use it as a search and replace tool.

Sed, AWK and regular expression based tools can work but can be a pain in some cases.

Wild Edit can work and is not that expensive.

My decision in the end is to work my Regular expression skills.

Edit
Report

2 Answers

4
cd $PROJECTDIR && find . -iname '*.*' -exec vim -c 's:^first line of text\nsecond line of text\n3rd line of text:new 1st line\rnew 2nd\rnew 3rd:' -c 'w!' -c 'q' {} \;

HTH

answered 2009-02-27T21:40:41.823
1

The best tool I've found is a piece of freeware called BK ReplaceEm. The interface takes a bit of getting used to, but it's worth learning how to use it. The tool is very powerful and allows you to do multi-line replaces with or without regular expressions.

answered 2009-02-12T10:39:25.150

Your Answer