案例十九将日志按天进行截取
#!/bin/bash
tody=`date +%F`
tomorrow=`date -d tomorrow +%F`
#例如:将error.log 文件中从 2024-04-08 到 2024-04-09(不包括 2024-04-09)的行写入到另一个文件
sed -n "/${tody}/,/${tomorrow}/{/${tomorrow}/!p}" error.log > error-${tody}.log
#例如:删除 error.log 文件中从 2024-04-08 到 2024-04-09(不包括 2024-04-09)的行
sed -i "/${tody}/,/${tomorrow}/{/${tomorrow}/!d}" error.log
sed -n "/${tody}/,/${tomorrow}/{/${tomorrow}/!p}" info.log > info-${tody}.log
sed -i "/${tody}/,/${tomorrow}/{/${tomorrow}/!d}" info.log