Linux Bash言語のコマンドラインにおいて、正規表現マッチした行が何行目かどうかを知りたい場合があります。
ag hogehoge links.txt | ag --only-matching "^\d+"
# or
grep -Fn hogehoge links.txt | sed -Ee 's/^([0-9]+).*/\1/g'
agのほうがシンプルですがagはマニュアルインストールできないので、レンサバとかだと使えないことがあります。その点grepであればエックスサーバーなんかでも使えるので。使い分けですね。
bash – How to get the line number of a match? – Stack Overflow