开发者

insert a string in the previous line and next line of a particular phrase/text

开发者 https://www.devze.com 2023-01-29 18:52 出处:网络
I want to ed开发者_如何学Cit a bunch of files in a folderusing a script/command as follows. Before :

I want to ed开发者_如何学Cit a bunch of files in a folder using a script/command as follows.

Before :

.
.
upc_barrier
.
.

After inserting:

.
.
start = clock();
upc_barrier
end  = clock() ;
.
.
.

Could any of you help me out ?


​The sed version:

sed -i 's/\(upc_barrier\)/start = clock\(\);\n\1\nend = clock\(\);/' FILES

Obviously replace FILES with whatever files you wish to operate on. The -i operator tells sed to write the modified stream back to the file.


If you do not mind to use perl

perl -pi -e "s/upc_barrier/start = clock();\nupc_barrier\nend  = clock() ;/g" ALL_FILES
0

精彩评论

暂无评论...
验证码 换一张
取 消