Solved

Need to reformat WWN string

Posted on 2008-10-31
7
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remote install of MSI file 4 55
Linux "time" command output redirection 16 257
batch file problem 5 79
Pass stdin text to Python subprocess 3 86
This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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