Trying to understand nested brackets in sed script

/^Host.*latency.*/{
    $!N
    /MAC Address/{
        s/.*(\(.*\)) .*MAC Address: \(.*\) .*/\1 -> \2/
    }
}  
/[Nn]map/d
s/^Host .*is up/& but MAC Address cannot be found/

I am trying to understand sed script as above. Can someone help me understand that I have never used sed as mentioned above. Its use

nmap -sP 192.168.1.0/20 | sed -f sedcript.sh
+3
source share
1 answer

If you mean nested parentheses in (\(.*\)). The outer pair is literal, and the inner, escaped pair captures the string corresponding to the closed regular expression. Backreference \1prints this captured line. \2backreference prints a string captured by a second pair of escaped brackets.

, . , ^Host.*latency.*, . $!N , . MAC Address, ( ).

:

  • /^Host.*latency.*/{ - ,
    • $!N - ,
    • /MAC Address/{ - ,
      • s/.*(\(.*\)) .*MAC Address: \(.*\) .*/\1 -> \2/ -
    • } - ,
  • } - ,
  • /[Nn]map/d - ( ) ,
  • s/^Host .*is up/& but MAC Address cannot be found/ -
+3
source

All Articles