以下有個例子,說明 sed 如何將檔案中: #include "../bbb/file.h" 這個字串中的 ../bbb 刪除,變成: #include "file.h" 指令如下: sed -i -r 's/(#include.*)\".*\/(.*\.h)\"/\1\"\2\"/g' ./file.cpp 其中 -i 代表作用在輸入檔案。 -r 代表要使用 regex。 如果要對某個資料夾內的所有檔案執行上述 sed 操作: find <folder_path> -type f -exec sed -i -r 's/(#include.*)\".*\/(.*\.h)\"/\1\"\2\"/g' {} \;
Coding for Passion, Solving Problems