solaris 10 + display 2 lines after match by grep?

0

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

yael

Posted 2012-10-18T15:00:13.433

Reputation: 27

1

Maybe like your previous post on unix.stackexchange ? http://unix.stackexchange.com/questions/52199/solaris-10-display-2-lines-after-match-by-grep/52200#52200

– Gilles Quenot – 2012-10-18T15:01:23.027

Answers

0

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)

Gilles Quenot

Posted 2012-10-18T15:00:13.433

Reputation: 3 111

0

This one would work on Solaris:

ggrep -A 2 'pattern' fileNames.ext

For example:

ggrep -A 5 -i 'pyCharm' myfile.txt

--- which will search for the case-insensitive pattern 'pyCharm' with 3 lines before the match and 5 after the match from the file myfile.txt

user5975913

Posted 2012-10-18T15:00:13.433

Reputation: 1