Linux grep command
I have a file, called test.txt which contains the bellow contents:
Mouse eats cheese.
Cat eats mouse.
Dog eats cat.
Lamb eats dog.
Worm eats lamb.
Print the line where "Dog" is availabe:
Dog eats cat.
Show line above and below of "Dog":
Cat eats mouse.
Dog eats cat.
Lamb eats dog.
If I provide - C 2 then output contains 2 lines above and below of the "Dog".
Mouse eats cheese.
Cat eats mouse.
Dog eats cat.
Lamb eats dog.
Worm eats lamb.
Print the line where "Dog" is availabe:
grep 'Dog' test.txtThe output will be:
Dog eats cat.
Show line above and below of "Dog":
grep -C 1 'Dog' test.txtThe output will be:
Cat eats mouse.
Dog eats cat.
Lamb eats dog.
If I provide - C 2 then output contains 2 lines above and below of the "Dog".
Comments
Post a Comment