Linux系统管理常用命令-sed
1.根据Apache Or Nginx 日志中的时间段来统计查看各种蜘蛛的大致爬取数据,命令格式就是
sed -n '/起始时间/,/结束时间/p' *.log | grep "匹配条件"
1 2 3 4 5 |
sed -n '/2013:13/,/2013:15:/p' www.access.log | \ egrep -i 'bot|crawler|slurp|spider' | grep "HTTP" | \ awk '{print $1,$2,$3,$4,$5,$6,$7}' | head -n 20 |
2.批量替换文件中的内容
1 |
sed -i "s/需要替换的内容/替换成的内容/g" `grep "匹配关键字" -rl .` |
3.向多个文件中添加内容,其中 $a\ 参数是必须的,后面跟需要添加的内容
1 2 3 4 5 |
sed -i '$a\需要添加的内容' file_name sed -i '$a\需要添加的内容' `find . -name file_name` sed -i '$a\需要添加的内容' file_name1 file_name2 file_name3 |
No Comments