Skip to main content
typo
Source Link
jamacoe
  • 488
  • 5
  • 14

To match a stingstring until a space, use [^ ]* The complete command would be:

ip a |sed -En "{N ; N ; s/^[1-9]: (.*: ).+\n?.+\n? {4}inet \  
([^ ]*).*/\1\2/p}"

Output:

lo: 127.0.0.1/8    
eno1: 192.168.1.44/24    
wlx68a3c45b2875: 192.168.1.36/24    

To match a sting until a space, use [^ ]* The complete command would be:

ip a |sed -En "{N ; N ; s/^[1-9]: (.*: ).+\n?.+\n? {4}inet \  
([^ ]*).*/\1\2/p}"

Output:

lo: 127.0.0.1/8    
eno1: 192.168.1.44/24    
wlx68a3c45b2875: 192.168.1.36/24    

To match a string until a space, use [^ ]* The complete command would be:

ip a |sed -En "{N ; N ; s/^[1-9]: (.*: ).+\n?.+\n? {4}inet \  
([^ ]*).*/\1\2/p}"

Output:

lo: 127.0.0.1/8    
eno1: 192.168.1.44/24    
wlx68a3c45b2875: 192.168.1.36/24    
Source Link
jamacoe
  • 488
  • 5
  • 14

To match a sting until a space, use [^ ]* The complete command would be:

ip a |sed -En "{N ; N ; s/^[1-9]: (.*: ).+\n?.+\n? {4}inet \  
([^ ]*).*/\1\2/p}"

Output:

lo: 127.0.0.1/8    
eno1: 192.168.1.44/24    
wlx68a3c45b2875: 192.168.1.36/24