nua7
1
Hi All,
I need to extract 543 from the command below :
[root@puiqtk06 ]# pvscan
PV /dev/sdb1 VG vg0 lvm2 [543.88 GB / 896.00 MB free]
Total: 1 [543.88 GB] / in use: 1 [543.88 GB] / in no VG: 0 [0 ]
I have the following command which does the job, but I think this could be achieved in a more simple way using sed or awk. Any help is appreciated.
pvscan | grep Total | tr -s " " | cut -d " " -f4 | tr -s "[" " " | cut -d "." -f1
hope this helps:
pvscan | grep Total |sed 's/\(.*\)\(\[[0-9][0-9][0-9]\)\(.*\)/\2/g'
or:
pvscan | awk -F '[[.]' '/Total/{print $2}'
nua7
4
Using awk command I get the following error :
[root@puiqtk06 ]# pvscan | awk -F '[[.]' '/Total/{print $2}'
awk: fatal: Unmatched [ or [^: /[[.]/
Using sed , we are pretty close except that "[" also comes in the value.
[root@puiqtk06 ]# pvscan | grep Total |sed 's/\(.*\)\(\[[0-9][0-9][0-9]\)\(.*\)/\2/g'
[543
[root@puiqtk06 ]#
Perhaps your awk likes the [ needs to be escaped:
pvscan | awk -F '[\[.]' '/Total/{print $2}'
or:
pvscan | sed -n '/Total/{s/[^[]*\[//;s/\..*//p}'
ohh it should have been
pvscan| grep Total|sed 's/\(.*\)\(\[\)\([0-9][0-9][0-9]\)\(.*\)/\3/g'
line=$(pvscan|grep Total)
line=${line#*\[}
echo ${line%%.*}
nua7
8
Works like a charm using both!
Thanks Scrutiniszer and shivdatta!! Appreciate all the help!