Skip navigation

Today’s awful-looking (though fairly tame) regular expression comes to you from my work at making my life, and the life of anyone who comes after me and still has to use our RADIUS server that much easier.

We make, edit, and delete entries from our RADIUS server’s database using the wlesscmd command which includes a list option that takes a string and gives back a list of entries that match that string. We use this in conjunction with the -n (note) option to give us an idea of who a particular MAC address belongs to when we’re looking at logs and whatnot. It’s also useful for doing housekeeping–we make a note of a student’s graduating year whenever we put one of their devices into the system so we can clear out batches of graduating students. The output of the list option looks something like this:

STUDENT 2010 Mike Jones lappy 1a2b3c4d5e6f STUDENT
STUDENT 2010 Janet Jones phone 0f9e8d7c6b5a STUDENT
STUDENT 2010 Frederick Wong lappy 5b8a9d4cfeef STUDENT

Which isn’t quite as nice as the comma-separated sheets that get used to add lots of devices all at once.

Enter the regexp.

sed -e 's/\([^ ]*[ ]*\)*\([0-9a-f]\{12,12\}\)\([ ]*[^ ]*\)/\2/g'

First, it looks for the note, which is any number of characters separated by any number of spaces any number of times: \([^ ]*[ ]*\)* . Then it looks for something that looks like a MAC address, which is exactly twelve hexidecimal numbers (0-f): \([0-9a-f]\{12,12\}\) . Finally, it looks for an SSID: \([ ]*[^ ]*\) . Then, sed takes just the MAC address, represented by \2 (the second regexp) and (in a code segment that isn’t included here) appends it to a temporary file of MACs prepped for removal.

This has been your scary-looking regular expression for the moment.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: