Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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/libsun_ima.so.1
com.sun.ima64           /usr/lib/64/libsun_ima.so.1
# Format:
#
# <library name>  <library pathname>
#

so I will get only the following lines:

com.sun.ima             /usr/lib/libsun_ima.so.1
com.sun.ima64           /usr/lib/64/libsun_ima.so.1
share|improve this question
1  
Maybe like your previous post on unix.stackexchange ? unix.stackexchange.com/questions/52199/… – 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

You must log in to answer this question.

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