Solved

Need to reformat WWN string

Posted on 2008-10-31
7
373 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
remove a combination of patterns from a file 15 65
powershell backup 2 123
AWS CLI - Instances, Volumes & Tagging 2 93
Debugging a shell script 3 25
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…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

776 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