0

From a log file on an AIX server, i need to get an extract as per below

File:

bla
bla

************
bla
UniqIdentifier
bla
UniqIdentifier
bla


************
bla
bla
bla

I need to retrieve

************
bla
UniqIdentifier
bla
UniqIdentifier
bla


************

Note: UniqIdentifier is initially used to go to the concerned part of the log file.

The objective is that this could be achieved in vi or using unix tools like AWK, GREP etc.

The pattern ************ is a delimiter in the log file, so for every UniqIdentifier we have the pattern. The idea here is to first locate the UniqIdentifier and from there look for the pattern ************ upward and from there go to the next ************ downward.

Pravin
  • 13
  • 4
  • The pattern ************ is a delimiter in the log file, so for every UniqIdentifier we have the pattern. The idea here is to first locate the UniqIdentifier and from there look for the pattern ************ upward and from there go to the next ************ downward. – Pravin Aug 08 '23 at 14:24
  • Can the input file contain other blocks between `************` lines that don't contain `UniqIdentifier. If yes, I suggest to show a longer example that also contains blocks without matching `UniqIdentifier`. Does the line ``************` always occur in pairs? Is there always an odd number of `************` before the block that may contain `UniqIdentifier`? Please [edit] your question and add this information. – Bodo Aug 08 '23 at 16:08
  • I don't think the linked possible duplicate solves the problem here. I understand the task as "print the block including the start/end markers, but only if it contains a line matching a pattern". `awk '/^\*{12}$/ { block=!block; if(!block && found) { print s $0; s="";found=0; } } block { s=s $0 RS } /^UniqIdentifier$/ && block { found=1; }' inputfile` – Bodo Aug 08 '23 at 16:31

0 Answers0