[gentoo-user] Need help with a regex

2008-05-24 Thread Robin Atwood
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+provide\s+\w /etc/init.d

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

TIA
-Robin












-- 
gentoo-user@lists.gentoo.org mailing list



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Andrey Falko
On Sat, May 24, 2008 at 11:22 AM, Robin Atwood
[EMAIL PROTECTED] 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+provide\s+\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+provide\s+\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



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Andrey Falko
On Sat, May 24, 2008 at 11:32 AM, Andrey Falko [EMAIL PROTECTED] wrote:
 On Sat, May 24, 2008 at 11:22 AM, Robin Atwood
 [EMAIL PROTECTED] 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+provide\s+\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+provide\s+\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



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Etaoin Shrdlu
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+provide\s+\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



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Robin Atwood
On Saturday 24 May 2008, Andrey Falko wrote:
 On Sat, May 24, 2008 at 11:32 AM, Andrey Falko [EMAIL PROTECTED] wrote:
  On Sat, May 24, 2008 at 11:22 AM, Robin Atwood
 
  [EMAIL PROTECTED] 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+provide\s+\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+provide\s+\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



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Alan McKinnon
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+provide\s+\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:

[EMAIL PROTECTED] /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
[EMAIL PROTECTED] /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
[EMAIL PROTECTED] /etc/init.d $ 
grep -e '^[[:space:]]+provide[[:space:]]+\w' /etc/init.d/*
[EMAIL PROTECTED] /etc/init.d $ 
  
-- 
Alan McKinnon
alan dot mckinnon at gmail dot com

-- 
gentoo-user@lists.gentoo.org mailing list



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Robin Atwood
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+provide\s+\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:[EMAIL PROTECTED]
Skype:  abend922
Yahoo:  abend922
--











-- 
gentoo-user@lists.gentoo.org mailing list



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Robin Atwood
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



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Alan McKinnon
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



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Wolf Canis
Robin Atwood wrote:
grep -e ^\s+provide\s+\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



signature.asc
Description: OpenPGP digital signature


Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Robin Atwood
On Saturday 24 May 2008, Alan McKinnon wrote:
 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:]]


Here for a start:
http://www.regular-expressions.info/charclass.html#shorthand

and also
http://doc.trolltech.com/3.3/qregexp.html#characters-and-abbreviations-for-sets-of-characters

Is it a Perl thing? Probably!
http://www.troubleshooters.com/codecorn/littperl/perlreg.htm#DoingStringComparisons

-Robin
-- 











-- 
gentoo-user@lists.gentoo.org mailing list



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Alan McKinnon
On Saturday 24 May 2008, Robin Atwood wrote:
 On Saturday 24 May 2008, Alan McKinnon wrote:
  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:]]

 Here for a start:
 http://www.regular-expressions.info/charclass.html#shorthand

 and also
 http://doc.trolltech.com/3.3/qregexp.html#characters-and-abbreviation
s-for-sets-of-characters

 Is it a Perl thing? Probably!
 http://www.troubleshooters.com/codecorn/littperl/perlreg.htm#DoingStr
ingComparisons

Ah yes, it's the old:

grep/sed/awk/vi/perl-implement-regexes-identically-except-when-they-don't 
thing again!


-- 
Alan McKinnon
alan dot mckinnon at gmail dot com

-- 
gentoo-user@lists.gentoo.org mailing list



Re: [gentoo-user] Need help with a regex

2008-05-24 Thread Wolf Canis
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

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

You have to use back slashed versions of meta characters. 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


-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg4dvkACgkQKT9zBKF0twURhwCZAQ/vK1la7X0mTuA2yTyWavqc
rEIAn1yr+ytPejcRXMr/d6f/Wkg4SgSc
=NQmh
-END PGP SIGNATURE-
-- 
gentoo-user@lists.gentoo.org mailing list