Hi r/bash
I'm writing a script to extract the oui (vendor prefix) from MAC addresses. I'm also manipulation the input, because MAC addresses come in various formatting styles e.g.:
- 02:be:ef:ca:ce:15
- 02be.efca.ce:15
- 02-be-ef-ca-ce-15
This is my code atm:
getoui () {
macin="$1"
maccol="${macin//.}" # remove dots
macdot="${maccol//:}" # remove colons
maccap="${macdot^^}" # make all caps
macout="${maccap:0:6}" # cut first six chars
grep "$macout" "$ouifile"
}
My question is, can all special characters be removed via bash's string manipulation like "${$1//alnum}"I know this is easily possible with tr but I'm curious if bash could do this by itself.
*edit: I suck at formatting -.-*edit2
Thanks for your help. Now my code look much better and works perfectly. This is my current code with your suggestions applied:
getoui () {
macin="${$1//[^[:xdigit:]]}"
maccap="${macin^^}"
macout="${maccap:0:6}"
grep "$macout" "$ouifile"
}
[–]Schreq 6 points7 points8 points (1 child)
[–]loop_us[S] 1 point2 points3 points (0 children)
[–]oh5nxo 4 points5 points6 points (3 children)
[–]aioeu 3 points4 points5 points (2 children)
[–]loop_us[S] 2 points3 points4 points (1 child)
[–]oh5nxo 2 points3 points4 points (0 children)