自己写了一个可以根据内容来截取需要看的部分的Shell
#test.sh
#使用方法:./test.sh test.txt "Oct 10" "Oct 11"
#!/bin/bash
a=$(sed -n "/$2 /=" $1 | sed -n '1p')
b=$(sed -n "/$3 /=" $1 | sed -n '1p')
sed -n "$a,$b p" $1 | sed '$d'
测试原文件:test.txt
un Oct 09 11:24:06 2011
CKPT started with pid=12, OS id=8011
Sun Oct 09 11:24:06 2011
SMON started with pid=13, OS id=8013
Mon Oct 10 11:24:06 2011
CKPT started with pid=12, OS id=8011
Mon Oct 10 11:24:06 2011
SMON started with pid=13, OS id=8013
Mon Oct 10 11:24:06 2011
RECO started with pid=14, OS id=8015
Mon Oct 10 11:24:06 2011
MMON started with pid=15, OS id=8017
Tue Oct 11 11:24:06 2011
MMON started with pid=15, OS id=8017
Tue Oct 11 11:24:08 2011
MMON started with pid=15, OS id=8017
输入命令:./test.sh test.txt "Oct 10" "Oct 11"
结果:
Mon Oct 10 11:24:06 2011
CKPT started with pid=12, OS id=8011
Mon Oct 10 11:24:06 2011
SMON started with pid=13, OS id=8013
Mon Oct 10 11:24:06 2011
RECO started with pid=14, OS id=8015
Mon Oct 10 11:24:06 2011
MMON started with pid=15, OS id=8017
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22736841/viewspace-710504/
,如需转载,请注明出处,否则将追究法律责任。