Skip to content

Instantly share code, notes, and snippets.

@chemzqm
Created December 20, 2015 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chemzqm/55a5246a5b218b9848dc to your computer and use it in GitHub Desktop.
Save chemzqm/55a5246a5b218b9848dc to your computer and use it in GitHub Desktop.
git grep with column and new files
#! /bin/bash
git --no-pager grep --no-color --no-index --exclude-standard -n $1 | while read git_grep; do
file_and_line=$(echo "$git_grep" | cut -d : -f 1,2)
match=$(echo "$git_grep" | sed 's/[^:]*:[^:]*:\(.*\)/\1/')
column=$(echo "$match" | awk "{print index(\$0, \"$1\")}")
echo "$file_and_line:$column:$match"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment