开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜