how to Show 5 lines after the match of a specific word like "Charlie" in ubuntu with terminal
Asked
Active
Viewed 245 times
-1
-
Pls add example string you want to match a word from – sumitya Jun 15 '16 at 18:38
-
Possible duplicate of [Grep a file, but show several surrounding lines?](http://stackoverflow.com/questions/9081/grep-a-file-but-show-several-surrounding-lines) – ti7 Jun 15 '16 at 18:38
-
Display 5 lines after the match of the word “Bombay”. @syadav – James Jun 15 '16 at 18:41
-
@syadav i am waiting for your answer – James Jun 15 '16 at 18:47
-
Welcome to SO community. Please refer [how to ask](http://stackoverflow.com/help/how-to-ask) to ask question in a better way. – sumitya Jun 15 '16 at 18:57
-
Display 5 lines after the match of the word “charlie”. please help on this @syadav – James Jun 15 '16 at 19:04
2 Answers
0
Below is the input file test.txt
$cat test.txt
Charlie:Harry:Ram
Charlie:Harry:Ram
Charlie:Harry:Ram
Charlie:Harry:Ram
Charlie:Harry:Ram
Charlie:Harry:Ram
Charlie:Harry:Ram
Run this command to get 5 lines.
grep Charlie test1|head -5
output:-
Charlie:Harry:Ram
Charlie:Harry:Ram
Charlie:Harry:Ram
Charlie:Harry:Ram
Charlie:Harry:Ram

sumitya
- 2,631
- 1
- 19
- 32
-
not like that gege gege Charlie a b c d e f this is the input and the out put comes like a b c d e f inshort after charlie 5 line comes @syadav – James Jun 15 '16 at 18:58
0
I believe the following is what you're looking for, but your question is not particularly clear. Please post more information, such as a section of the file you're searching in if this doesn't answer your question!
grep -A 5 "Charlie" myfile.txt

ti7
- 16,375
- 6
- 40
- 68