查找固定字符串和git提交

查找含有console.log的文件具体行,并打印git 提交用户,字符串截取参考链接

test.bash
#!/bin/bash

searhstr="console.log"
bashfile="test.bash"

for line in `grep -rn $searhstr . --exclude=$bashfile`

do

    # echo "line: $line"

    # 获取file
    file=${line%%:*}
    # echo "file: $file"

    # 获取行号
    linenum=${line%:*}
    linenum=${linenum#*:}
    # echo "linenum: $linenum"


    # 获取git提交用户
    author=`git blame -p -L $linenum $file | grep "^author "`
    author=${author#* }
    # echo $author


    echo "$file $linenum $author"
done