【问题标题】:UNIX: How to change all instances of a string within all files in a directoryUNIX:如何更改目录中所有文件中字符串的所有实例
【发布时间】:2016-03-16 12:31:38
【问题描述】:

我的问题和上一个问题基本一样……

How to change all occurrences of a word in all files in a directory

...除了我试图更改对头文件的引用。

例如,我正在尝试将 [lessthan]abc/filename.h[greaterthan] 更改为 "filename.h",这甚至可以使用相同的语法,还是我应该寻找一个快速的程序来完成它?

谢谢

【问题讨论】:

  • 您可以使用多种工具轻松完成此操作。最常见的选择可能是 sed 或 perl。

标签: unix ubuntu


【解决方案1】:

您可以通过sed轻松做到这一点:

sed -i -e 's,<abc/filename.h>,"filename.h",' *

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-23
    • 1970-01-01
    • 2017-05-14
    • 2013-02-20
    • 2011-04-22
    • 2012-02-12
    • 2019-03-01
    • 2013-08-05
    相关资源
    最近更新 更多