Hello I am working on a small script that will allow me to parse information from an input. This is working, but i Know that there is a better way to have done this. Please, I am trying to learn [self taught] so tear me up. The input would be as follows:
C7-0-4-U1 36.5 mHz IN7-0-4-0 567 mHz 00:15:d0:e3:b0:41 online(pt) 10.106.156.129 42.0 -0.5 35.1 -3.0 38.7 0.0E+000 0.0E+000 9 0 12:20:32 AM rZ5 1
C7-0-4-U1 36.5 mHz IN7-0-4-0 567 mHz 2c:9e:5f:de:ed:36 w-online(pt) 10.113.52.11 36.5 0.0 35.1 -5.0 37.7 4.9E-006 0.0E+000 9 0 12:20:32 AM r4G 0
C7-0-4-U1 36.5 mHz IN7-0-4-0 567 mHz e4:83:99:6d:57:ad w-online(pt) 10.113.45.239 43.5 0.0 35.1 -4.6 39.5 5.8E-006 0.0E+000 8 0 12:20:34 AM r4G 0
C7-0-4-U1 36.5 mHz IN7-0-4-0 567 mHz 3c:75:4a:9c:7b:92 w-online(pt) 10.109.238.61 42.2 -0.5 33.9 -14.4 34.6 4.9E-006 0.0E+000 199 4 12:20:33 AM rC2 0
The Desired Output would be as follows:
00:15:D0:E3:B0:41 10.106.156.129
2C:9E:5F:DE:ED:36 10.113.52.11
E4:83:99:6D:57:AD 10.113.45.239
3C:75:4A:9C:7B:92 10.109.238.61
The Code that I have is as follows:
#GET INPUT FROM CLIPBOARD
set Input [sh_set clipboard]
#REMOVE ALL EXCESSIVE WHITESPACE
regsub -all {\s{3,}} $Input "\n" CleanInput
#SET THE INPUT AS LIST
set List [split $CleanInput "\n"]
#GET LIST ITEMS
set Cust1 [lindex $List 1]
set Cust2 [lindex $List 2]
set Cust3 [lindex $List 3]
set Cust4 [lindex $List 4]
regexp -all {(?:[[:xdigit:]]{2}([.-:]))(?:[[:xdigit:]]{2}\1){4}[[:xdigit:]]{2}} $Cust1 C1MacAddress
regexp -all {10\.(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){2}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)} $Cust1 C1IpAddress
regexp -all {(?:[[:xdigit:]]{2}([.-:]))(?:[[:xdigit:]]{2}\1){4}[[:xdigit:]]{2}} $Cust2 C2MacAddress
regexp -all {10\.(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){2}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)} $Cust2 C2IpAddress
regexp -all {(?:[[:xdigit:]]{2}([.-:]))(?:[[:xdigit:]]{2}\1){4}[[:xdigit:]]{2}} $Cust3 C3MacAddress
regexp -all {10\.(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){2}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)} $Cust3 C3IpAddress
regexp -all {(?:[[:xdigit:]]{2}([.-:]))(?:[[:xdigit:]]{2}\1){4}[[:xdigit:]]{2}} $Cust4 C4MacAddress
regexp -all {10\.(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){2}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)} $Cust4 C4IpAddress
return "$C1MacAddress\t$C1IpAddress\n$C2MacAddress\t$C2IpAddress\n$C3MacAddress\t$C3IpAddress\n$C4MacAddress\t$C4IpAddress"
Well, assuming that we load it from a txt file, that would be how I’d do it:
And I just thought it could be fancy if you could say which customer is which ^^. You can remove the part ‘Customer $count’ and any lines involving ‘$count’ if you don’t need that extra feature.
Or if the input data is in table form (meaning the information you need are in the same columns, I’d go for: