我有一個包含 102 個子目錄和 1590 個檔案的目錄。我試圖對所有檔案遞回運行以下命令,包括名稱中帶有空格的檔案,以將 400 個標簽的串列從 更改#tag為[[link]].
find . -name '*.md' | xargs sed -i -f sedfile *.md
它僅適用于檔案名中沒有空格的檔案。sedfile 的格式為s/#tag/[[link]]/g
sed: can't read ./4.Programming/G-Code/List: No such file or directory
sed: can't read of: No such file or directory
sed: can't read Common: No such file or directory
sed: can't read G-Code: No such file or directory
sed: can't read Commands: No such file or directory
sed: can't read and: No such file or directory
sed: can't read What: No such file or directory
sed: can't read They: No such file or directory
sed: can't read Mean.md: No such file or directory
檔案名為 4.Programming/G-Code/List of Common G-Code Commands and What They Mean.md。
我以前用過
find . -type f -name "*.md" -print0 | xargs -0 sed -i '' -e 's/#tag/[[link]]/g'
單獨進行更改,但我不期待手動更改 390 多個。
當我嘗試將這兩者結合起來時
find . -name '*.md' print0 | xargs -0 sed -i -f sedfile *.md
我得到
find: paths must precede expression: `print0`
到目前為止,我在研究中發現的文章展示了如何對單個檔案進行多次更改或對多個檔案進行一次更改。如何編輯兩個示例中的任何一個以覆寫目錄中的 *.md 檔案?
uj5u.com熱心網友回復:
有一個錯字:你使用print0而不是-print0.
您也不需要*.md, 因為xargs正在提供檔案名。
這應該有效:
find . -name '*.md' -print0 | xargs -0 sed -i -f sedfile
您也可以-exec改用:
find . -name '*.md' -exec sed -i -f sedfile {}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/348803.html
