开发者

find and replace command for whole directoray issue

开发者 https://www.devze.com 2023-04-11 15:16 出处:网络
see i have one jig.c file in tha开发者_如何学运维t i have statement like mkvFree(jig); Now i have used following command for find and replace

see i have one jig.c file in tha开发者_如何学运维t i have statement like

mkvFree(jig);

Now i have used following command for find and replace

find /home/jeegar/jig.c -type f -exec sed -i 's/mkvFree(/mkvFree((void**)&/g' {} \;

By this command i want to get output as

mkvFree((void**)&jig);

But i get output like

mkvFree((void**)mkvFree(jig);

whats wrong with my command ?

Edit :

i have taken this command from https://superuser.com/questions/324428/find-and-replace-command-for-whole-directory


You need to escape the \& character:

find /home/jeegar/jig.c -type f -exec \
       sed -i 's/mkvFree(/mkvFree((void**)\&/g' {} \;

The & character would substitute the whole matched input for the pattern.


& is a metacharacter in the replacement expression, meaning "the whole search string". Quote it and it should work.

0

精彩评论

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

关注公众号