Super User is a question and answer site for computer enthusiasts and power users. 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

how to match string , and display the two line under the string

for example ( I want to match the "manufacture" string and display the two lines after

cat ima.conf   

# the manufacturer or driver author.

com.sun.ima             /usr/lib/
com.sun.ima64           /usr/lib/64/
# Format:
# <library name>  <library pathname>

so I will get only the following lines:

com.sun.ima             /usr/lib/
com.sun.ima64           /usr/lib/64/
share|improve this question
Maybe like your previous post on unix.stackexchange ?… – Gilles Quenot Oct 18 '12 at 15:01
up vote 0 down vote accepted

This is an awk solution :

grep="pattern" # the string where we begin
max=4          # the number of lines after the matched pattern
awk '/'"$grep"'/{l=1;count=NR;next} l>0 && NR-count < '"$max"+1' {print}'

(tested on Solaris11)

share|improve this answer

Your Answer


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.