I've managed to use back-ticks to store my df -lh
command as a variable, $var
, but I would like to split it up so that each part of the variable can be assigned to another variable.
Here is my output when I print $var
:
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk0s2 931Gi 82Gi 849Gi 9% 21503280 222477462 9% /
/dev/disk1s2 19Gi 5.0Gi 14Gi 27% 1303373 3579438 27% /Volumes/Install OS X Yosemite
/dev/disk1s3 1.8Ti 174Gi 1.6Ti 10% 45714072 437656799 9% /Volumes/store
What I would like is to remove the first line of headers, then split it down into the following categories of:
$filesystem
, $size
, $used
, $avail
, $cap
, $mounted
.
I've tried using shift to get rid of the first line, but I am aware now that this is only for arrays. For a different array I have, I use chomp, i.e.
foreach my $line (@output) {
chomp $line;
my( $filesystem, $size, $used, $avail, $cap, $mounted ) = split (/\s+/, $line);
}
But as this is not an array, I don't know how to go about it, unless there is a way to store my system output as an array?
Many thanks.