Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 8 down vote accepted

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
share|improve this answer
1  
Awesome!! Didn't know grep could do that. Thank you very much! – sanjan May 27 '10 at 4:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.