grep until last match code example
Example 1: grep until last match
grep -n [match] #shows line numbers of matched lines
Example 2: grep until third match
Just combine grep with head command for filtering only the first match as:
grep "match" | head -n 1 #Change 1 to not only match first but further matches