Thursday, April 25, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 3619  / 1 Year ago, fri, january 13, 2023, 11:28:40

I want to display three or four lines before and after a certain string in a really huge file, which I can' topen with vi. How is this done?



I tryed



grep -i -n -r 'mysearchstring'


but this only gives me one line. I need some lines before and after to get the context!



Thanks!



I once have seen a terminal command, that does that, but I forgot and I can't find it again. :/


More From » command-line

 Answers
5

Use grep with the -A (how many lines to display after the match) and -B (how man lines to display before the match) parameters:



grep -i -n -r -A 4 -B 4 'mysearchstring' file.xml

[#44895] Saturday, January 14, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
girdleas

Total Points: 1
Total Questions: 112
Total Answers: 114

Location: Lesotho
Member since Wed, Jun 2, 2021
3 Years ago
girdleas questions
;