Skip to content

Instantly share code, notes, and snippets.

@purplexa
Created October 29, 2015 00:19
Show Gist options
  • Select an option

  • Save purplexa/e7a6e90dfae25aafff9c to your computer and use it in GitHub Desktop.

Select an option

Save purplexa/e7a6e90dfae25aafff9c to your computer and use it in GitHub Desktop.
Use grep to print all lines after a match
function grep_to_end () {
if [ -z $1 -o -z $2 ]; then
echo "Usage:\ngrep_to_end 'regex' file1 [file2 file3 ...]"
exit 2
fi
for i in $(grep -n -m1 $1 "${@:2}"); do
filename="$(cut -d':' -f1 <<< $i)"
lnum="$(cut -d':' -f2 <<< $i)"
echo "\n--\n$filename:"
tail -n +$lnum $filename
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment