Tuesday, May 02, 2023

Search and display surrounding lines in log file

 grep -n 'search_string' /path/to/log/file.log | cut -d: -f1 | xargs -I {} awk 'NR >= {} - 50 && NR <= {} + 50' /path/to/log/file.log | sed -n '1,101p'