2016-11-29 40 views
0
find . -type f -path '*/browser/components/*/*.react.js' -exec sed -i "" '1 i\ 
import { logRender } from "../../../common/lib/logger"; 
' {} + 

上面的命令只會僅執行1個文件,第一個,而不是從每個結果:有什麼是我錯過了UNIX - 不能執行從查找文件的每個結果

find . -type f -path '*/browser/components/*/*.react.js'

+1

也許事情是,該'{} +'建設提出由'find'發現了一個文件列表..考慮到它替換到'{}; '。 (像往常一樣,您可能需要跳過';':'{} \;'。) –

回答

0

你可以試試這個;

find . -type f -path '*/browser/components/*/*.react.js' -exec sed -i "" '1 i\ 
import { logRender } from "../../../common/lib/logger"; 
' {} \; 
0

使用SED的-s--separate)選項:

-s, --separate

考慮文件作爲單獨的,而不是作爲一個單一的連續長流。

因爲找到-exec command +動作通過在末端附加每個選擇的文件名建立的命令。特別是,將使用多個文件調用sed命令:sed ... file1 file2 file3 ...

否則,請按照find -exec sed -i '...' {} ';'的順序處理文件。

順便說一下,很可能您使用的是GNU SED,因爲i\命令是GNU擴展。使用GNU SED,您無需爲-i選項指定參數。

此外,請考慮通過-e--expression)選項傳遞SED腳本以避免含糊不清。

?例如:

find . -type f -path '*/browser/components/*/*.react.js' -exec sed -s -i -e '1 i\ 
import { logRender } from "../../../common/lib/logger"; 
' {} +