How to display when nth line match a pattern?

Hi All,
I have sample of listing as following

Database 2 entry:

Database alias = PXRES
Database name = PXRES
Local database directory = /db2/data1/db2phnx
Database release level = d.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =

Database 3 entry:

Database alias = CMNGI
Database name = CMNGI
Node name = CMNGI1F
Database release level = d.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =

AS you can see the 8th line contains the Directory Entry type = Remote or Indirect

How to just display 3rd line when the 8th line is match "Indirect" ?

Thanks.

you can use awk for this (assuming you have 1 or more blank lines between each database entry):

awk '/Directory entry type = Indirect/ {
   split($0, L, "\n")
   print L[3]
}' RS= infile

3rd line, 8th line,...counting from where? Is the lines marked in red your naming scheme? Do you want the line that says Database alias?

1 Like

Yes good point Aia - print statement in the code above may need to change to print L[1] above if the OP is after the "Database alias" line.