1

I'm looking for a command to get text around a specific line of a file.

ex: file content:

a

b

c

d

e

f

g

h

i

j

a command like: ]$ commandname -text f -lines 3 giving the output

c

d

e

f

g

h

i

1 Answer 1

8

Assuming you're running a *nix:

grep -C 3 f filename

If you want x lines before f and y lines after:

grep -A y -B x f filename
1
  • 1
    Awesome!! Didn't know grep could do that. Thank you very much!
    – sanjan
    May 27, 2010 at 4:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .