FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 01-04-2010, 07:53 PM
"Mr. X"
 
Default OT: piped greps with regex

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 'startsectors+d+'| grep -Po 'd+'
32

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

--
Mark




_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-04-2010, 08:14 PM
Les Mikesell
 
Default OT: piped greps with regex

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 'startsectors+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@gmail.com
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-04-2010, 08:59 PM
Stephen Harris
 
Default OT: piped greps with regex

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 'startsectors+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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 04:31 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org