[CentOS] OT: piped greps with regex

Mon Jan 4 20:53:45 UTC 2010
Mr. X <tlviewer at yahoo.com>

List,

Happy NY.

>From the bash command below, I'm trying to parse out the startsector value:
$ sudo file mini_vusb.img
mini_vusb.img: x86 boot sector, Microsoft Windows XP MBR, Serial 0x25d84; partition 1: ID=0xe, active, starthead 1, startsector 32, 390496 sectors

First try was with grep/egrep but I wanted to capture 'startsector 32' as a group (). Nothing came close to working. Fail 1

Next attempt was with Perl
file mini_vusb | perl -lane '$i=0 ;for (@F) {print substr($F[$i+1],0,-1) if ($_ eq "startsector"); $i++}'

the above works, but it's too much fire power for the job :)
Actually I came up with it in a minute or two once I remembered the special var @F. Success 1

Last effort led to this
$ sudo file mini_vusb.img | grep -Po 'startsector\s+\d+'| grep -Po '\d+'
32

I like this best. Is there a way to shorten it up?

-- 
Mark