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:
grep 'Dog' test.txt
The output will be:
  Dog eats cat.

Show line above and below of "Dog":
grep -C 1 'Dog' test.txt
The 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

Popular posts from this blog

There is a process already using the admin port 4848 -- it probably is another instance of a GlassFish server; ERROR

How to Convert OutputStream to InputStream

How to compile and install GraphicsMagick (GM) in Linux