solaris 10 + display 2 lines after match by grep?

by yael   Last Updated August 13, 2019 21:01 PM

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
Tags : grep sed solaris awk


Answers 2


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
Gilles Quenot
October 18, 2012 15:22 PM

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
user5975913
August 13, 2019 20:35 PM

Related Questions




Zipping / Encryption on Solaris 10

Updated June 16, 2015 12:00 PM

inconsistency between pfiles and fuser

Updated December 06, 2015 08:00 AM

Update Java version, Solaris 10

Updated July 26, 2018 10:01 AM