Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing columns 1

Status
Not open for further replies.

cryptoadm

MIS
Nov 6, 2008
71
US
Code:
#!/usr/bin/perl

sub get_alldgs {
        @alldg_list=();
        @alldg_list=`/usr/sbin/vxdisk -o alldgs list 2> /dev/null`;
        foreach $item (@alldg_list) {
        my @f = split(" ", $item, 9999);
        $alldg_device = $f[1];
        $alldg_type = $f[2];
        $alldg_disk = $f[3];
        $alldg_group = $f[4];
        $alldg_status = $f[5];
             printf "%20s     %10s    %10s     %10s     %30s\n", $alldg_device, $alldg_type, $alldg_disk, $alldg_group, $alldg_status;
        }
}

&get_alldgs
The above only prints columns 2-5 but isn't printing column 1 probably because my split uses a space which separates all columns.

How do I get it to print all five columns?

Thanks.
 
Without seeing the data your code is parsing its impossible to say. Whats the '9999' argument for in the split function?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Output:
# vxdisk -o alldgs list
DEVICE TYPE DISK GROUP STATUS
c0t0d0s2 sliced rootdisk rootdg online
c1t0d0s2 sliced rootmirror rootdg online
c3t18d1s2 sliced - (datadg) online
c3t18d2s2 sliced - (datadg) online
c3t18d3s2 sliced - (datadg) online
c3t18d4s2 sliced - (datadg) online
c3t18d5s2 sliced - (datadg) online
c3t18d6s2 sliced - (datadg) online
c3t18d7s2 sliced - (datadg) online
c3t18d8s2 sliced - (datadg) online
c3t18d9s2 sliced - (datadg) online
c3t18d10s2 sliced - (secdg) online
c3t18d23s2 sliced - (appdg) online
c3t18d30s2 sliced data01 datadgX online
c3t18d31s2 sliced data02 datadgX online
c3t18d32s2 sliced data03 datadgX online
c3t18d33s2 sliced data04 datadgX online
c3t18d34s2 sliced data05 datadgX online
c3t18d35s2 sliced data06 datadgX online
c3t18d36s2 sliced data07 datadgX online
c3t18d37s2 sliced data08 datadgX online
c3t18d38s2 sliced data09 datadgX online
c3t18d39s2 sliced sec01 secdgX online
c3t18d52s2 sliced app01 appdgX online
 
The code is printing columns 2-5 of the output above, but I also want column one printed.
 
try this:

Code:
my @f = split([red]/\s+/[/red], $item, 9999);

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I changed
Code:
        $alldg_device = $f[1];
        $alldg_type = $f[2];
        $alldg_disk = $f[3];
        $alldg_group = $f[4];
        $alldg_status = $f[5];
to
Code:
        $alldg_device = $f[0];
        $alldg_type = $f[1];
        $alldg_disk = $f[2];
        $alldg_group = $f[3];
        $alldg_status = $f[4];
This printed the columns 1-5 like I wanted but I thought the counting started at 1 and not zero.
 
not in perl, the first position of an array is zero [0].

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top