Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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/… –  sputnick Oct 18 '12 at 15:01
add comment

1 Answer

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
add comment

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.