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
05-24-2008, 03:28 PM
Etaoin Shrdlu
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 -rE '^[[:space:]]+provide[[:space:]]+dns' /etc/init.d
--
gentoo-user@lists.gentoo.org mailing list
05-24-2008, 03:32 PM
"Andrey Falko"
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
05-24-2008, 03:33 PM
"Andrey Falko"
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
05-24-2008, 03:43 PM
Robin Atwood
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
05-24-2008, 03:44 PM
Alan McKinnon
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
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
05-24-2008, 03:50 PM
Robin Atwood
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: