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 回答