-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sed的p是打印,d是删除,取反! #92
Comments
一个取日志的脚本 日志格式
|
function get_last_inode_log()
{
if [ -z $1 ]; then
if [ $(cat $LOG_FILE | tail -n 20 |grep -c "M CST") -eq 0 ]; then
cat $LOG_FILE | tail -n 20
else
cat $LOG_FILE | tail -n 20 | sed '1,/M CST/d'
fi
return
fi
local inode=$1
local first_no=$(cat $LOG_FILE | grep -n $inode | awk -F":" 'NR==1{print $1}')
local first_no_before_10=$((first_no-10))
sed -n ${first_no_before_10},${first_no}'p' $LOG_FILE | sed '1,/M CST/d'
local last_no=$(cat $LOG_FILE | grep -n $inode | awk -F":" 'END{print $1}')
local last_no_after_20=$((last_no+20))
sed -n $(($first_no+1)),$((last_no-1))'p' $LOG_FILE
sed -n ${last_no},${last_no_after_20}'p' $LOG_FILE | sed '1,/run \[/!d'
}
|
代码写的很丑 cat $LOG_FILE | grep -n $inode | awk -F":" '{print $1}'
410
411
412
413
414
415
416
417
418 first_no=410 往前找10行,然后删掉匹配到的date行之前的,sed '1,/PM CST/d' |
不知道有没有更好的实现 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sed的p是打印,d是删除,取反!
The text was updated successfully, but these errors were encountered: