2

ファイルを検索して、検索する文字列の前に行を追加する方法を見つけようとしています

xxx =  text() // '=' folowed by space or not then  'text()'

見つかった場合:

この行の前に追加

new text

言い換えれば、私はこれが欲しい

xxx =  text()

これになる:

new text
xxx =  text()

私はこれを試しました

find /var/www/users/ \( -name '*.py'   \)  -type f  -exec sed -i 's|\s+\=\s+\text()|new text|i' {} \;
4

1 に答える 1

2

私は次のようにします。

find -iname '*.py' -and -type f | xargs sed -i -e '/= *text()/ i new text'
于 2012-07-07T14:48:34.440 に答える