OT: piped greps with regex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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



      
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux