Solved

Need to reformat WWN string

Posted on 2008-10-31
7
370 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 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

22 Experts available now in Live!

Get 1:1 Help Now