I have been scouring the web for ways to search across multiple lines of output and then print the lines which contain the strings I care about. I am actually running this on a checkpoint firewall, and the command is as follows: cphaprob -ia list when I execute that I get various lines of output. (below). What I have tried to do is grep, sed, or pcregrep the output of the command to return only certain parts. My thought was that I could export the value of position 'x' by using awk, then printing my own echo command with the variable. But I have to get only the lines I care about first. I want to print the lines which show the Device Name and the 'state'. I would prefer to do this in-line rather than outputting the values to a file and running a command against it. Something along the lines of
cphaprob -ia list | grep Name | grep state
I know the above example won't work for various reasons, but it expresses what I am trying to do. I want to have the shell print in a nice format something along the following:
Device Name:x
Current State:y
and nothing else. there are extemporaneous words on some of the lines such as timeout and time since last report that I don't want displayed.
I can't use Perl.
Does anybody have a suggestion?
P.S., the output below are actually on different lines, but I can't get the output on this website to display it as separate lines. For example, Device Name: Problem Notification Current state: OK is actually two lines. Current state is the next line. Similarly for the rest of the output as well.
[Expert@firewall:0]# cphaprob -ia list
Built-in Devices:
Device Name: Problem Notification
Current state: OK
Device Name: Interface Active Check
Current state: OK
Device Name: HA Initialization
Current state: OK
Device Name: Load Balancing Configuration
Current state: OK
Device Name: Recovery Delay
Current state: OK
Registered Devices:
Device Name: Synchronization
Registration number: 0
Timeout: none
Current state: OK
Time since last report: 60485.9 sec
Device Name: Filter
Registration number: 1
Timeout: none
Current state: OK
Time since last report: 60484.8 sec
Device Name: cphad
Registration number: 2
Timeout: none
Current state: OK
Time since last report: 437745 sec
Device Name: fwd
Registration number: 3
Timeout: none
Current state: OK
Time since last report: 2.76118e+06 sec
Device Name: routed
Registration number: 4
Timeout: none
Current state: OK
Time since last report: 60478.4 sec
{}
code tool in the StackExchange editor to mark literal code and output that should not be reformatted.