I think what you're asking is how to zero-pad the hexadecimal elements of the colon-separated string in the third field. That's (perhaps surprisingly) hard to do in awk
because:
- the
%s
(string) format specifier doesn't support zero-padding (neither in awk
nor in the underlying C function AFAIK)
and
- if you use the appropriate numeric format
%02x
then the arguments are implicitly converted as decimal digits first (discarding a-f as garbage) - resulting in incorrect hexadecimal values.
If you have GNU awk, you can manipulate and convert hex digits using the --non-decimal-data
command line option, however the elements themselves need to be prefixed with 0x
to force the conversion. So for example
gawk --non-decimal-data '
gsub(/[[:xdigit:]][[:xdigit:]]?/,"0x&",$3) && split($3,a,":") {
$3=sprintf("%02x:%02x:%02x:%02x:%02x:%02x",a[1],a[2],a[3],a[4],a[5],a[6])
} 1' OFS='\t' file
ABC 22.22.28.97 00:00:0c:9f:f0:d9
ABC 22.22.28.109 00:50:56:64:49:f3
ABC 22.22.28.110 00:50:56:68:55:8e
It's somewhat simpler in perl
where you can use the hex
function and simple regex substitution:
perl -alne '$F[2] =~ s/([[:xdigit:]]{1,2})/sprintf "%02x", hex($1)/ge , print join "\t", @F' file
ABC 22.22.28.97 00:00:0c:9f:f0:d9
ABC 22.22.28.109 00:50:56:64:49:f3
ABC 22.22.28.110 00:50:56:68:55:8e
convert ***awk '{print $3}'
but I get an error: convert: unable to open image. Please tell me the exact command that you are giving.