sed
来源:互联网 发布:网络电影脱轨下载 编辑:程序博客网 时间:2021/01/26 16:22
1. 文本替换
方法1: sed -i 's/被替换的内容/要替换成的内容/' file
方法2:
sed 's/被替换的内容/要替换成的内容/g' file > file.out
mv file.out file
这里注意:
不能这样做:
sed 's/被替换的内容/要替换成的内容/g' file > file
这样只会清空源文件。
例如:
sed 's/\r//g' whitelist_20120828.txt > waaa 去掉window文本文件得\r ,使linux下文本正常显示
3.批量改
sed -i "s/oldstring/newstring/g" `grep oldstring -rl yourdir`
例如:替换/home下所有文件中的www.bcak.com.cn为bcak.com.cn
sed -i "s/www.bcak.com.cn/bcak.com.cn/g" `grep www.bcak.com.cn -rl /home`