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 > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 05-24-2008, 03:22 PM
Robin Atwood
 
Default Need help with a regex

Regexs are not my strong point! I am trying to get a list of service scripts
that provide virtual services. Each such script contains a line like:

provide dns

i.e. the line starts with one or more spaces, followed by the text "provide",
followed by one or more spaces and a single word. i have come up with:

grep -e ^s+provides+w /etc/init.d

but, as usual, nothing is matched. What am I doing wrong?

TIA
-Robin












--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 03:28 PM
Etaoin Shrdlu
 
Default Need help with a regex

On Saturday 24 May 2008, 17:22, Robin Atwood wrote:

> Regexs are not my strong point! I am trying to get a list of service
> scripts that provide virtual services. Each such script contains a
> line like:
>
> provide dns
>
> i.e. the line starts with one or more spaces, followed by the text
> "provide", followed by one or more spaces and a single word. i have
> come up with:
>
> grep -e ^s+provides+w /etc/init.d
>
> but, as usual, nothing is matched. What am I doing wrong?

On my system, no initscript has the line "provide dns" in it, so it might
be possible that you don't have any file with that line.

That said, you should use -r, and you don't need the -e switch:

grep -r '^[[:space:]]{1,}provide[[:space:]]{1,}dns' /etc/init.d

or, perhaps clearer

grep -rE '^[[:space:]]+provide[[:space:]]+dns' /etc/init.d
--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 03:32 PM
"Andrey Falko"
 
Default Need help with a regex

On Sat, May 24, 2008 at 11:22 AM, Robin Atwood
<robin.atwood@attglobal.net> wrote:
> Regexs are not my strong point! I am trying to get a list of service scripts
> that provide virtual services. Each such script contains a line like:
>
> provide dns
>
> i.e. the line starts with one or more spaces, followed by the text "provide",
> followed by one or more spaces and a single word. i have come up with:
>
> grep -e ^s+provides+w /etc/init.d

Right now you are saying: match one or more spaces in the begining
followed by provide followed by one or more spaces followed by *one*
word followed by one space and followed by /etc/init.d

I think you mean: grep -e ^s+provides+w+ /etc/init.d
>
> but, as usual, nothing is matched. What am I doing wrong?
>
> TIA
> -Robin
>
>
>
>
>
>
>
>
>
>
>
>
> --
> gentoo-user@lists.gentoo.org mailing list
>
>
--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 03:33 PM
"Andrey Falko"
 
Default Need help with a regex

On Sat, May 24, 2008 at 11:32 AM, Andrey Falko <ma3oxuct@gmail.com> wrote:
> On Sat, May 24, 2008 at 11:22 AM, Robin Atwood
> <robin.atwood@attglobal.net> wrote:
>> Regexs are not my strong point! I am trying to get a list of service scripts
>> that provide virtual services. Each such script contains a line like:
>>
>> provide dns
>>
>> i.e. the line starts with one or more spaces, followed by the text "provide",
>> followed by one or more spaces and a single word. i have come up with:
>>
>> grep -e ^s+provides+w /etc/init.d
>
> Right now you are saying: match one or more spaces in the begining
> followed by provide followed by one or more spaces followed by *one*
> word followed by one space and followed by /etc/init.d
>
> I think you mean: grep -e ^s+provides+w+ /etc/init.d
>>
>> but, as usual, nothing is matched. What am I doing wrong?
>>
I see your mistake....w means alphanumeric character, not word.
>> TIA
>> -Robin
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> gentoo-user@lists.gentoo.org mailing list
>>
>>
>
--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 03:43 PM
Robin Atwood
 
Default Need help with a regex

On Saturday 24 May 2008, Andrey Falko wrote:
> On Sat, May 24, 2008 at 11:32 AM, Andrey Falko <ma3oxuct@gmail.com> wrote:
> > On Sat, May 24, 2008 at 11:22 AM, Robin Atwood
> >
> > <robin.atwood@attglobal.net> wrote:
> >> Regexs are not my strong point! I am trying to get a list of service
> >> scripts that provide virtual services. Each such script contains a line
> >> like:
> >>
> >> provide dns
> >>
> >> i.e. the line starts with one or more spaces, followed by the text
> >> "provide", followed by one or more spaces and a single word. i have come
> >> up with:
> >>
> >> grep -e ^s+provides+w /etc/init.d
> >
> > Right now you are saying: match one or more spaces in the begining
> > followed by provide followed by one or more spaces followed by *one*
> > word followed by one space and followed by /etc/init.d
> >
> > I think you mean: grep -e ^s+provides+w+ /etc/init.d
> >
> >> but, as usual, nothing is matched. What am I doing wrong?
>
> I see your mistake....w means alphanumeric character, not word.

I had just realised that myself. However, it still doesn't work.
Thanks for trying, though.

-Robin










--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 03:44 PM
Alan McKinnon
 
Default Need help with a regex

On Saturday 24 May 2008, Robin Atwood wrote:
> Regexs are not my strong point! I am trying to get a list of service
> scripts that provide virtual services. Each such script contains a
> line like:
>
> provide dns
>
> i.e. the line starts with one or more spaces, followed by the text
> "provide", followed by one or more spaces and a single word. i have
> come up with:
>
> grep -e ^s+provides+w /etc/init.d
>
> but, as usual, nothing is matched. What am I doing wrong?

"grep -e" is not the same thing as "egrep" or "grep -E", and
I never managed to get s to work as a synonym for [[:space:]]
Plus you need a proper file glob i your file spec

Try:
egrep '^[[:space:]]+provide[[:space:]]+w' /etc/init.d/*

As in:

alan@nazgul /etc/init.d $
egrep '^[[:space:]]+provide[[:space:]]+w' /etc/init.d/*
/etc/init.d/courier-authlib: provide authdaemond
/etc/init.d/hwclock: provide clock
/etc/init.d/net.eth0: provide net
/etc/init.d/net.lo: provide net
/etc/init.d/net.lo.openrc.bak: provide net
/etc/init.d/net.wlan0: provide net
/etc/init.d/postfix: provide mta
/etc/init.d/shorewall: provide firewall
/etc/init.d/syslog-ng: provide logger
/etc/init.d/vixie-cron: provide cron
alan@nazgul /etc/init.d $
grep -E '^[[:space:]]+provide[[:space:]]+w' /etc/init.d/*
/etc/init.d/courier-authlib: provide authdaemond
/etc/init.d/hwclock: provide clock
/etc/init.d/net.eth0: provide net
/etc/init.d/net.lo: provide net
/etc/init.d/net.lo.openrc.bak: provide net
/etc/init.d/net.wlan0: provide net
/etc/init.d/postfix: provide mta
/etc/init.d/shorewall: provide firewall
/etc/init.d/syslog-ng: provide logger
/etc/init.d/vixie-cron: provide cron
alan@nazgul /etc/init.d $
grep -e '^[[:space:]]+provide[[:space:]]+w' /etc/init.d/*
alan@nazgul /etc/init.d $
--
Alan McKinnon
alan dot mckinnon at gmail dot com

--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 03:50 PM
Robin Atwood
 
Default Need help with a regex

On Saturday 24 May 2008, Etaoin Shrdlu wrote:
> On Saturday 24 May 2008, 17:22, Robin Atwood wrote:
> > Regexs are not my strong point! I am trying to get a list of service
> > scripts that provide virtual services. Each such script contains a
> > line like:
> >
> > provide dns
> >
> > i.e. the line starts with one or more spaces, followed by the text
> > "provide", followed by one or more spaces and a single word. i have
> > come up with:
> >
> > grep -e ^s+provides+w /etc/init.d
> >
> > but, as usual, nothing is matched. What am I doing wrong?
>
> On my system, no initscript has the line "provide dns" in it, so it might
> be possible that you don't have any file with that line.
>
> That said, you should use -r, and you don't need the -e switch:
>
> grep -r '^[[:space:]]{1,}provide[[:space:]]{1,}dns' /etc/init.d
>
> or, perhaps clearer
>
> grep -rE '^[[:space:]]+provide[[:space:]]+dns' /etc/init.d

I am looking for all the scripts with lines like "provide xxx", not just the
dns service. That said, your solution did the trick! I amended the expression
to:

grep -rE '^[[:space:]]+provide[[:space:]]+w+' /etc/init.d

and got what I was after. But why does "[[:space:]]+" work and "s+" fail?

Cheers
-Robin
--
------------------------------------------------------
Robin Atwood, Bangkok, Thailand.
tel/fax: +66 2252 1438
mobile: +66 851 322487
MSN: robin@binro.org
Skype: abend922
Yahoo: abend922
------------------------------------------------------











--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 03:54 PM
Robin Atwood
 
Default Need help with a regex

On Saturday 24 May 2008, Alan McKinnon wrote:

> "grep -e" is not the same thing as "egrep" or "grep -E", and
> I never managed to get s to work as a synonym for [[:space:]]

I was wondering about that!

> Plus you need a proper file glob i your file spec
That was a typo in my post.

> Try:
> egrep '^[[:space:]]+provide[[:space:]]+w' /etc/init.d/*

Thanks, I am in business now.

Cheers
-Robin
--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 03:57 PM
Alan McKinnon
 
Default Need help with a regex

On Saturday 24 May 2008, Robin Atwood wrote:
> But why does "[[:space:]]+" work and "s+" fail?

Apparently because s is not a synonym for [[:space:]]

I've heard this one before but never got it to work and never seen it in
writing. Do you have a reference for where you read it?

--
Alan McKinnon
alan dot mckinnon at gmail dot com

--
gentoo-user@lists.gentoo.org mailing list
 
Old 05-24-2008, 04:03 PM
Wolf Canis
 
Default Need help with a regex

Robin Atwood wrote:
> grep -e ^s+provides+w /etc/init.d
>
> but, as usual, nothing is matched. What am I doing wrong?

You have to use back slashed versions of metacharacters. Following
how would do that:

$ grep -e '^[[:space:]]+provide[[:space:]]+[a-z]+' /etc/init.d/*
/etc/init.d/syslog-ng: provide logger
/etc/init.d/vixie-cron: provide cron


W. Canis
 

Thread Tools




All times are GMT. The time now is 12:27 AM.

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