我有很多的源代碼需要修改,只需從如何用引號
#include <headerA.h>
到
#include "headerA.h"
我已經嘗試了一些的sed,awk的命令,但不能代替尖括號完全確定如何進行此操作。我正在開發Ubuntu平臺。任何輸入將不勝感激!
我有很多的源代碼需要修改,只需從如何用引號
#include <headerA.h>
到
#include "headerA.h"
我已經嘗試了一些的sed,awk的命令,但不能代替尖括號完全確定如何進行此操作。我正在開發Ubuntu平臺。任何輸入將不勝感激!
這將做到這一點:
sed -i '/^#include/s/[<>]/"/g' filename
開頭的/^#include/
地址告訴sed
只在與#include
開頭的行執行替換。 [<>]
是一個與eith <
或>
匹配的正則表達式,它們將被替換爲"
,並且g
修飾符會告訴它替換該行上的所有出現,而不僅僅是第一個出現。
首先使用find
與sed
然後用mv
find . -name <ol_file_nme> -exec sed 's/[<>]/"/g' '{}' \; -print > <new_file_name>
mv <new_file_name> <ol_file_nme>
這應該修改代替每個文件:
find . -name '*.[ch]' -exec \
sed -i 's|^#include[[:blank:]]\{1,\}<\([^>]\{1,\}\)>[[:blank:]]*$|#include "\1"|' '{}' \;
只是一個說法,你用'。* $'後面沒有引用的evental信息結束。 – NeronLeVelu
是的,我應該使用'[[:blank:]] *'來代替,這是完全正確的。我會編輯答案。 – djhaskin987
這可能爲你工作(GNU SED):
sed '/#include/y/<>/""/' file
專注於包含標題和翻譯的行(y/.../.../
)所需的字符。
find /Your/Source/Path \
-name '*.[ch]' \
-exec \
sed -i '/^#include[[:blank:]]/ s/<\([^>]*\)>/"\1"/g' "{}" \
\;
將改變:
.h
或.c
任何文件/Your/Source/Path
<>
具有相同的文字surrouonding用雙引號
#include
el pluse uno使用'find',但注意@ barmar關於'<' and '>'字符的其他用途的明智告誡和解決方案; -) 祝你們好運。 – shellter