I am trying to process multiple mac addresses from output of a program. Output is in below format -

Device B0:CA:68:CF:88:54 dev1
Device DC:16:B2:AE:FB:8F dev2
Device B0:CA:68:CF:88:11 dev3
Device DC:16:B2:AE:FB:22 dev4

I want to store mac addresses along with their names in a file And I want to store mac addresses in a variable and process further.

I am struggling with it in Expect. How to do it ? Please help

Below command works but only gives single Mac -

expect -re "Device.*(\[0-9A-Z]\[0-9A-Z]:\[0-9A-Z]\[0-9A-Z]:\[0-9A-Z]\[0-9A-Z]:\[0-9A-Z]\[0-9A-Z]:\[0-9A-Z]\[0-9A-Z]:\[0-9A-Z]\[0-9A-Z])"

1 Answer 1


If you don't need to interact with this program, you can exec it and capture the output easily:

set output [exec some_program]

set macs [lmap line [split $output \n] {lindex [split $line] 1}]

Ref: exec, lmap

If the program needs interaction, it's a little trickier to capture the output. Let me know.

  • Thanks. It worked. Jan 18, 2020 at 7:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .