have a mac address and I need to replace only one hex char (one at a very specific position) by a different random one (it must be different than the original). I have it done in this way using xxd and it works:
#!/bin/bash
mac="00:00:00:00:00:00" #This is a PoC mac address obviously :)
different_mac_digit=$(xxd -p -u -l 100 < /dev/urandom | sed "s/${mac:10:1}//g" | head -c 1)
changed_mac=${mac::10}${different_mac_digit}${mac:11:6}
echo "${changed_mac}" #This echo stuff like 00:00:00:0F:00:00
The problem for my script is that using xxd
means another dependency... I want to avoid it (not all Linux have it included by default). I have another workaround for this using hexdump
command but using it I'm at the same stage... But my script already has a mandatory awk
dependency, so... Can this be done using awk
? I need an awk
master here :) Thanks.