2015/12/30

Awk

Filter specific lines via regex,
extract specific field from filtered lines,
summarize the extracted field values
and print the sum


awk 'match($0, /Some value: (\d+)$/, ary) {sum += ary[1]} END {print sum}' lines.txt

Get current git branch fast:
alias br='git rev-parse --abbrev-ref HEAD'
alias br='awk -F/ "{print \$NF}" .git/HEAD'

2015/12/03

Bash: search two lines in a file

grep -rl 'use Module1' . | xargs -I{} grep -l 'use Module2' '{}'

ag -l 'use Module1' | xargs -I{} ag -l 'use Module2' '{}'