Operating System - HP-UX
1753797 Members
7338 Online
108805 Solutions
New Discussion юеВ

easy way to convert this into one single line file

 
SOLVED
Go to solution
kholikt
Super Advisor

easy way to convert this into one single line file

Hi

I have the cisco switch config file in this format. Basically it is a zone name with the zone member alias and WWN
============================
zone name NOCVMHOST19_HBA1_CX4_486_SPA_P4 vsan 10
fcalias name NOCVMHOST19_HBA1 vsan 10
pwwn 10:00:00:00:c9:74:16:11

fcalias name CX4_486_SPA_P4 vsan 10
pwwn 50:06:01:64:44:60:2d:da

zone name NOCVMHOST19_HBA1_CX4_486_SPB_P4 vsan 10
fcalias name NOCVMHOST19_HBA1 vsan 10
pwwn 10:00:00:00:c9:74:16:11

fcalias name CX4_486_SPB_P4 vsan 10
pwwn 50:06:01:6c:44:60:2d:da
============================

I wish to convert it into the following format so that I can easily import into excel file. Basically each line is consist of the zone name, first zone member alias, wwn and second zone member alias wwn. Can this be done via normal shell script?

NOCVMHOST19_HBA1_CX4_486_SPA_P4 NOCVMHOST19_HBA1 10:00:00:00:c9:74:16:11 CX4_486_SPA_P4 50:06:01:64:44:60:2d:da
NOCVMHOST19_HBA1_CX4_486_SPB_P4 NOCVMHOST19_HBA1 10:00:00:00:c9:74:16:11 CX4_486_SPB_P4 50:06:01:6c:44:60:2d:da
abc
2 REPLIES 2
Earl_Crowder
Trusted Contributor
Solution

Re: easy way to convert this into one single line file

Awk:

awk '/zone name/{printf("\n%s ", $3);}/fcalias name/{printf("%s ",$3);}/pwwn/{printf("%s ",$2);}END{printf("\n");}' zonefilename
James R. Ferguson
Acclaimed Contributor

Re: easy way to convert this into one single line file

Hi:

You could do:

# cat ./refomat
#!/usr/bin/perl
use strict;
use warnings;
local $/ = "";
my ( $zone, $alias_1, $wwn_1, $alias_2, $wwn_2 );
while (<>) {
if ( m{^zone} ) {
( $zone, $alias_1, $wwn_1 ) =
m{zone name (\S+).+fcalias name (\S+).+pwwn (\S+)}s;
}
elsif ( m{^fcalias} ) {
( $alias_2, $wwn_2 ) =
m{fcalias name (\S+).+pwwn (\S+)}s;
print "$zone $alias_1 $wwn_1 $alias_2 $wwn_2\n";
}
}
1;

...run as:

# ./reformat configfile

Regards!

...JRF...