sed 与 find 命令结合使用
目的:把/root/kang目录下,所有带有*.sh结尾的文件,并且内容oldboy的字符串,替换成kang
[[email protected] kang]# find /root/kang/ -type f -name "*.sh"|xargs
/root/kang/nginx/abc.sh /root/kang/test.sh #查出总共有两个文件
[[email protected] kang]# find /root/kang/ -type f -name "*.sh"|xargs cat #查看文件内容
oldboy
oldboy
[[email protected] kang]# find /root/kang/ -type f -name "*.sh"|xargs sed ‘s#oldboy#kang#g‘ #查找替换,并打印出来(原文件并没有更改)
kang
kang
[[email protected] kang]# find /root/kang/ -type f -name "*.sh"|xargs sed -i ‘s#oldboy#kang#g‘ #查找并替换原文件内容
[[email protected] kang]# find /root/kang/ -type f -name "*.sh"|xargs cat
kang
kang
[[email protected] kang]#
原文地址:http://blog.51cto.com/12965094/2113144
时间: 2024-10-07 17:45:29