Solved

Need to reformat WWN string

Posted on 2008-10-31
7
368 Views
Last Modified: 2013-12-26
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"
0
Comment
Question by:jools
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 22848614
WWN="0123456789012345"
WWN=`echo $WWN  | perl -lpe '$_=join":",unpack"(a2)*"'`
0
 
LVL 48

Accepted Solution

by:
Tintin earned 400 total points
ID: 22848625

echo 0123456789012345 | sed "s/\(..\)/\1:/g"

Open in new window

0
 
LVL 84

Expert Comment

by:ozo
ID: 22848639
echo 0123456789012345 | sed "s/\(..\)/\1:/g"
gives an extra : at the end
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Assisted Solution

by:Rowley
Rowley earned 100 total points
ID: 22848749
echo $WWN | sed "s/\(..\)/\1:/g;s/:$//"

fixes that.
0
 
LVL 13

Expert Comment

by:Rowley
ID: 22848835
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.


0
 
LVL 19

Author Comment

by:jools
ID: 22849026
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.
0
 
LVL 19

Author Closing Comment

by:jools
ID: 31511974
Thanks Guys,

It would have been nice to see a perl fix as well (always good to keep options open and learn new things).
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now