Junos
Highlighted
Junos

Print NUM lines of trailing context after matching lines.

‎07-05-2019 05:04 AM

Hello all

 

Wondering is it possible somehow with Juniper to match on something in a show command and also display the next or previous line(s)?

 

For instance in SROS (Alcatel/Nokia) you have the option of "pre/post-lines" or "-B/-A" in Linux.

 

Thanks

Daniel

4 REPLIES 4
Junos

Re: Print NUM lines of trailing context after matching lines.

‎07-05-2019 05:25 AM

Hi, 

 

I found you could do this by dropping to the shell and executing the commands:

> start shell
% cli show interfaces terse lo0.0 | grep up
lo0.0                   up    up   inet     172.16.2.1          --> 0/0
% cli show interfaces terse lo0.0 | grep -A 1 up
lo0.0                   up    up   inet     172.16.2.1          --> 0/0
                                            192.168.99.1        --> 0/0

https://kb.juniper.net/InfoCenter/index?page=content&id=KB31557&actp=RSS

Hope this helps.

 

Ashvin

Highlighted
Junos
Solution
Accepted by topic author Zozimus
‎07-10-2019 01:55 AM

Re: Print NUM lines of trailing context after matching lines.

‎07-05-2019 05:26 AM

Hi Daniel,

 

On Junos box operational mode I am unsure if we have an option like that but you may have a hack via shell.

 

root@jtac% cli show chassis routing-engine > /var/tmp/test.txt


root@jtac% grep -C 5 "User" /var/tmp/test.txt
Temperature 40 degrees C / 104 degrees F
CPU temperature 37 degrees C / 98 degrees F
DRAM 3313 MB (16384 MB installed)
Memory utilization 16 percent
5 sec CPU utilization:
User 0 percent
Background 0 percent
Kernel 2 percent
Interrupt 0 percent
Idle 98 percent
Model RE-S-1800x4


root@jtac% grep -A 5 "User" /var/tmp/test.txt
User 0 percent
Background 0 percent
Kernel 2 percent
Interrupt 0 percent
Idle 98 percent
Model RE-S-1800x4


root@jtac-srx5400-r2005% grep -B 5 "User" /var/tmp/test.txt
Temperature 40 degrees C / 104 degrees F
CPU temperature 37 degrees C / 98 degrees F
DRAM 3313 MB (16384 MB installed)
Memory utilization 16 percent
5 sec CPU utilization:
User 0 percent
root@jtac%

 

Regards,

 

Rahul

Regards,
Rahul
Highlighted
Junos

Re: Print NUM lines of trailing context after matching lines.

‎07-05-2019 05:55 AM

Excellent, I hadn't even thought of the shell Smiley Frustrated

 

Still, would be very nice if they had it available from CLI.

 

Cheers!

 

Daniel

Highlighted
Junos

Re: Print NUM lines of trailing context after matching lines.

‎07-05-2019 04:16 PM

For following lines on a single occurance you can use find instead of match.  Find will start the outpu with the matched text and all that follows it.

 

Steve Puluka BSEET - Juniper Ambassador
IP Architect - DQE Communications Pittsburgh, PA (Metro Ethernet & ISP)
http://puluka.com/home
Feedback