Junos OS

last person joined: 21 hours ago 

Ask questions and share experiences about Junos OS.
  • 1.  Print NUM lines of trailing context after matching lines.

    Posted 07-05-2019 05:04

    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



  • 2.  RE: Print NUM lines of trailing context after matching lines.

     
    Posted 07-05-2019 05:25

    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



  • 3.  RE: Print NUM lines of trailing context after matching lines.
    Best Answer

    Posted 07-05-2019 05:27

    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



  • 4.  RE: Print NUM lines of trailing context after matching lines.

    Posted 07-05-2019 05:56

    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



  • 5.  RE: Print NUM lines of trailing context after matching lines.

    Posted 07-05-2019 16:17

    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.