Manipulating bash parameters
You can do it by manipulating bash parameters, remove the colons, then insert the dots between 4-character strings. See the chapter about 'Parameter Expansion' in man bash
for details.
The following shellscript file script
can do what you want,
#!/bin/bash
function converter {
tmp0="$1"
tmp1=${tmp0//:/}
#echo "$tmp1"
tmpstr="${tmp1:0:4}.${tmp1:4:4}.${tmp1:8:4}"
echo "$tmpstr"
}
#######
# main
#######
if test -s "$1"
then
while read line
do
converter "$line"
done < "$1"
else
echo "Usage: ${0##*/} <file-with-list-of-macs>"
fi
Example: I made a small input file macs
ab:cd:ef:gh:ij:kl
12:ab:34:cd:56:ef
qw:er:ty:as:df:gh
and run the following command,
$ ./script macs
abcd.efgh.ijkl
12ab.34cd.56ef
qwer.tyas.dfgh
Command line with sed
You can also use sed
doing almost the same as above: remove the colons, then insert the dots after 4-character strings, and finally you must remove the extra dot at the end of each line,
$ < macs sed -e 's/\://g' -e 's/..../&./g' -e 's/\.$//'
abcd.efgh.ijkl
12ab.34cd.56ef
qwer.tyas.dfgh
With a huge input file this solution with sed
is significantly faster than the bash shellscript.
< huge.in sed -e 's/\://g' -e 's/..../&./g' -e 's/\.$//' > huge.out