且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多行搜索替换工具

更新时间:2023-12-05 14:48:22

sed 可以满足您的需求.

在此处查看关于此的常见问题解答条目 http://sed.sourceforge.net/sedfaq4.html#s4.23.3

如果你需要匹配一个静态块文本(可能出现任意数量的整个文件中的次数),其中块的内容在提前,那么这个脚本很容易使用

Sed 可用于 Windows.参见 http://gnuwin32.sourceforge.net/packages/sed.htm>

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.

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