I have data output in the below format. I get this output from a command on console.
Number: 9
state: Online
Data: W1F-9YN
Device: 41
Number: 10
state: Online
Inquiry Data: W1-9YN
Device: 41
Number: 11
state: Online
Inquiry Data: W1-9YN
Device: N/A
Number: 42
state: Online
Data: WD-W WDZ-04J
But, now I want to change it to output in a table format. Like as shown below
Device number state data
41 10 online WY1-996
42 12 offline WY2-996
. . . .
. . . .
. . . .
I tried doing with code given below, but I am not able to arrange in right format and some time all data shows up in a single column. Could anyone help me out ?
open WDLIST, "Command";
while (<WDLIST>) {
if (m/Device\s*:\s*(\d+)/) {
$enDevice = $1;
print "$enDevice";
}
if (m/Number\s*:\s*(\d+)/) {
$umber = $1;
print "$Number";
chomp;
}
if (m/state\s*:\s*(w+)/) {
$State = $1;
print"$State";
}
if (m/Data\s*:\s*(w+)(d+)(\-)(\s)/) {
$Data = $1;
print"$Data";
}
}
Thank You!