Getting the line number of the nth match
If we're aiming to find the line number of the nth match, we might think to use grep
and parse it's output.
Take this markdown document for example, where we want to find the line number of the second occurrence of ---
:
input.md
This gets the job done, but it invokes a number of subshells, reducing performance. An alternative using awk
may be less I/O intensive:
Last updated