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.
It's easy to do multiline replace in Notepad++. You have to use \n to represent the newline in your string, and it works for both search and replace strings. You have to make sure to select "Extended" search mode in the bottom left corner of the search window. This is in a file already open.
CHANGE: The default keyboard shortcut for “Multiline Find/Replace” was Ctrl+Alt+F but it was not applied because this shortcut was already taken by “F# Interactive”. So, the new default shortcut is Ctrl+M, Ctrl+F.
Cntrl+C the above text you want to find and Cntrl+V it into a new blank document in Notepad++, then Select it again and hit Cntrl+F . You will see your text into the "find" field with tabbed spaces as the line breaks. No need for plugins. Confirmed in Notepad++ 6.6.
The JetBrains family of IDEs: IntelliJ, RubyMine, PHPStorm etc. will do a multi-line search and replace.
Select the text in question and press ctrl-shift-F
-- this will open the replace dialog with the selected text as the find expression (using a regex with newlines escaped as \n
)
sed will do what you want.
See the FAQ entry about exactly this here http://sed.sourceforge.net/sedfaq4.html#s4.23.3
If you need to match a static block of text (which may occur any number of times throughout a file), where the contents of the block are known in advance, then this script is easy to use
Sed is available for Windows. See http://gnuwin32.sourceforge.net/packages/sed.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With