美文网首页
查找异常上下文

查找异常上下文

作者: 果酱一一 | 来源:发表于2016-05-26 12:27 被阅读17次
    #!/bin/bash
    number=$1;
    msg=$1;
    file=$2;
    
    if [ $1 ]; then
            msg=$1;
    else
            echo "msg is empty";
        exit 1;
    fi;
    
    if [ $2 ]; then
            file=$2;
    else
            echo "filename is empty";
        exit 2;
    fi;
    
    
    if [ $3 ]; then
        last=$3;
    else
        last=5;
    fi;
    
    
    if [ $4 ]; then
        length=$4;
    else 
        length=10;
    fi;
    
    echo $number,$file;
    
    let "number=$number+5";
    
    echo $number;
    
    list=`cat -n $file | grep -i $msg | cut -f1`
    
    for iter in $list
    do
      echo $iter;
      number=$iter;
      let "number=$number+$last";
      head -n $number $file | tail -n $length
    done;
    
    # head -n $number $file | tail -n 10
    
    

    相关文章

      网友评论

          本文标题:查找异常上下文

          本文链接:https://www.haomeiwen.com/subject/kwqxdttx.html