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

sanjan
  • 13
  • 3

1 Answers1

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
sh-beta
  • 6,838
  • 7
  • 47
  • 66