I am using @"df -lH | grep \"/Volumes/*\" | awk '{$1=$2=$3=$4=$5=$6=$7=$8\"\"; print $0 }'" for getting locally-mounted volumes path. but if volume name contain two or more space (Leopard 1). its(awk) removing space from output.
Output:
$df -lH
Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s3 81G 61G 19G 77% /
/dev/disk0s2 81G 72G 8.2G 90% /Volumes/Leopard 1 2 3
/dev/disk0s4 158G 47G 111G 30% /Volumes/Backup
$ df -lH | grep "/Volumes/*"
/dev/disk0s2 81G 72G 8.2G 90% /Volumes/Leopard 1 2 3
/dev/disk0s4 158G 47G 111G 30% /Volumes/Backup
$ df -lH | grep "/Volumes/*" | awk '{$1=$2=$3=$4=$5=""; print $0}'
/Volumes/Leopard 1 2 3
/Volumes/Backup
can anyone please help me out?
By default
awk‘s output field separator is a single space. So the output of yourawkcommand is completely expected. To get the result you want, you’ll need to use some sort of regex, so try this instead withGNU awk:Or if you have
GNU sed:Results:
EDIT:
I see that
BSD/OSX awkdoesn’t support interval expressions unfortunately. Therefore the safest way would be to do this withawk:or with
sed:This should also be highly portable! HTH.
EDIT:
For Mac OSX 10.8 with 8 columns, simply extend the regex:
or with
sed: