Julian Parker
asked on
Need to reformat WWN string
Hi All,
I need a quick fix;
I have a load of WWN's in the format "0123456789012345"; I need them reformatted to "01:23:45:67:89:01:23:45"
I need a quick fix;
I have a load of WWN's in the format "0123456789012345"; I need them reformatted to "01:23:45:67:89:01:23:45"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
echo 0123456789012345 | sed "s/\(..\)/\1:/g"
gives an extra : at the end
gives an extra : at the end
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Similarly, I get an error when trying out your suggestion:
[root@centos01 tmp]# cat file1
0123456789012345
[root@centos01 tmp]# cat wwn2
#!/usr/bin/perl
#
while (<>) {
$_=join":",unpack"(a2)*";
print;
}
[root@centos01 tmp]# ./wwn2 file1
Not enough arguments for unpack at ./wwn2 line 4, near ""(a2)*";"
Execution of ./wwn2 aborted due to compilation errors.
[root@centos01 tmp]# cat file1
0123456789012345
[root@centos01 tmp]# cat wwn2
#!/usr/bin/perl
#
while (<>) {
$_=join":",unpack"(a2)*";
print;
}
[root@centos01 tmp]# ./wwn2 file1
Not enough arguments for unpack at ./wwn2 line 4, near ""(a2)*";"
Execution of ./wwn2 aborted due to compilation errors.
ASKER
Thanks guys,
I just got out of the meeting and knew you'd come thru :-)
I got the right result with this;
WWN=`echo "${U_WWN}" | sed -e 's/-/:/g' | sed -e 's/0x//' | sed -e "s/\(..\)/\1:/g;s/:$//"`
I'd still be interested to see the perl workaround though.
I just got out of the meeting and knew you'd come thru :-)
I got the right result with this;
WWN=`echo "${U_WWN}" | sed -e 's/-/:/g' | sed -e 's/0x//' | sed -e "s/\(..\)/\1:/g;s/:$//"`
I'd still be interested to see the perl workaround though.
ASKER
Thanks Guys,
It would have been nice to see a perl fix as well (always good to keep options open and learn new things).
It would have been nice to see a perl fix as well (always good to keep options open and learn new things).
WWN=`echo $WWN | perl -lpe '$_=join":",unpack"(a2)*"'