FAQ
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

Search Discussions

  • Les Mikesell at Jan 4, 2010 at 9:14 pm

    Mr. X wrote:
    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?

    sed -ne 's/.*startsector \([0-9]*\).*/\1/p'
    But I'd have used perl. Your firepower is even more wasted sitting idle
    than running perl - and perl can probably do whatever your next step was
    going to be in the same program.

    --
    Les Mikesell
    lesmikesell at gmail.com
  • Stephen Harris at Jan 4, 2010 at 9:59 pm

    On Mon, Jan 04, 2010 at 12:53:45PM -0800, Mr. X wrote:

    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?
    Use the correct tool; "sed"

    sed 's/^.* startsector \(.*\),.*$/\1/'

    --

    rgds
    Stephen

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcentos @
categoriescentos
postedJan 4, '10 at 8:53p
activeJan 4, '10 at 9:59p
posts3
users3
websitecentos.org
irc#centos

People

Translate

site design / logo © 2023 Grokbase