有人可以提出一种优雅的方法来实现这一目标吗?
输入:
test instant ()
test instant ()
...
test instant () //total 1000 lines
Run Code Online (Sandbox Code Playgroud)
输出应该是:
test instant1 ()
test instant2 ()
test instant1000()
Run Code Online (Sandbox Code Playgroud)
空行在我的输入文件中,同一目录下有许多文件需要同时处理。
我试图用这个来替换同一个目录中的许多文件,但没有用。
test instant ()
test instant ()
...
test instant () //total 1000 lines
Run Code Online (Sandbox Code Playgroud)
错误:
Substitution replacement not terminated at -e line 1.
Substitution replacement not terminated at -e line 1.
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
test instant1 ()
test instant2 ()
test instant1000()
Run Code Online (Sandbox Code Playgroud)
它起作用了,但索引只是从一个文件增加到另一个文件。我想在更改为新文件时将其重置为 1。有什么好的建议吗?
for file in ./*; do perl -i -000pe 's/instance$& . ++$n/ge' "$file"; done …Run Code Online (Sandbox Code Playgroud) 输入:
line1 with the PATTERN that contains ( )
line2 with the PATTERN that contains ( )
lineN with the PATTERN that contains ( )
Run Code Online (Sandbox Code Playgroud)
输出:
line1 with the PATTERN that contains ( ) ;
line2 with the PATTERN that contains ( ) ;
...
lineN with the PATTERN that contains ( ) ;
Run Code Online (Sandbox Code Playgroud)
我试过这个:
find . -name "test.txt" -print | xargs sed -i "/PATTERN/ s/$)/); /g"
Run Code Online (Sandbox Code Playgroud)
但它没有用。