sed to display the pattern string, the line above it and the first line of that para
I need to grep for a particular string and if found need to display the line containing that string, the line above that and also the first line of that paragraph.
Can this be done via sed.
Thanks,
Eg, My Paragraphs
OA connectA
Enclosure:
Status: OK
Unit Identification LED: Off
Onboard Administrator:
Status: Critical
Power Subsystem:
Status: OK
Cooling Subsystem:
Status: OK
OA connectB
Interconnect Module #1 Status:
Health LED: OK
Interconnect Module #2 Status:
Health LED: Degraded
Interconnect Module #5 Status:
Health LED: OK
Interconnect Module #6 Status:
Here, if I grep for Critical, it should display the following
OA connectA <- The first line of the paragraph
Onboard Administrator: <- The line above the pattern string
Status: Critical <- The line containing the pattern string
similarly if I grep for Degraded, it should display
OA ConnectB
Interconnect Module #2 Status:
Health LED: Degraded
|