grep surrounding context

Updated: 16 July 2023

Find tell in trans.sql and show 3 lines of context surrounding the result

grep -C 3 tell trans.sql

Show 3 context lines before and 2 lines after matches

grep -B 3 -A 2 bar index.php

Show --only-matching parts of the matching line

grep -o foo index.php

Leave a comment