Gentoo Archives: gentoo-user

From: Alan McKinnon <alan.mckinnon@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Need help with a regex
Date: Sat, 24 May 2008 15:45:18
Message-Id: 200805241744.03146.alan.mckinnon@gmail.com
In Reply to: [gentoo-user] Need help with a regex by Robin Atwood
1 On Saturday 24 May 2008, Robin Atwood wrote:
2 > Regexs are not my strong point! I am trying to get a list of service
3 > scripts that provide virtual services. Each such script contains a
4 > line like:
5 >
6 > provide dns
7 >
8 > i.e. the line starts with one or more spaces, followed by the text
9 > "provide", followed by one or more spaces and a single word. i have
10 > come up with:
11 >
12 > grep -e ^\s+provide\s+\w /etc/init.d
13 >
14 > but, as usual, nothing is matched. What am I doing wrong?
15
16 "grep -e" is not the same thing as "egrep" or "grep -E", and
17 I never managed to get \s to work as a synonym for [[:space:]]
18 Plus you need a proper file glob i your file spec
19
20 Try:
21 egrep '^[[:space:]]+provide[[:space:]]+\w' /etc/init.d/*
22
23 As in:
24
25 alan@nazgul /etc/init.d $
26 egrep '^[[:space:]]+provide[[:space:]]+\w' /etc/init.d/*
27 /etc/init.d/courier-authlib: provide authdaemond
28 /etc/init.d/hwclock: provide clock
29 /etc/init.d/net.eth0: provide net
30 /etc/init.d/net.lo: provide net
31 /etc/init.d/net.lo.openrc.bak: provide net
32 /etc/init.d/net.wlan0: provide net
33 /etc/init.d/postfix: provide mta
34 /etc/init.d/shorewall: provide firewall
35 /etc/init.d/syslog-ng: provide logger
36 /etc/init.d/vixie-cron: provide cron
37 alan@nazgul /etc/init.d $
38 grep -E '^[[:space:]]+provide[[:space:]]+\w' /etc/init.d/*
39 /etc/init.d/courier-authlib: provide authdaemond
40 /etc/init.d/hwclock: provide clock
41 /etc/init.d/net.eth0: provide net
42 /etc/init.d/net.lo: provide net
43 /etc/init.d/net.lo.openrc.bak: provide net
44 /etc/init.d/net.wlan0: provide net
45 /etc/init.d/postfix: provide mta
46 /etc/init.d/shorewall: provide firewall
47 /etc/init.d/syslog-ng: provide logger
48 /etc/init.d/vixie-cron: provide cron
49 alan@nazgul /etc/init.d $
50 grep -e '^[[:space:]]+provide[[:space:]]+\w' /etc/init.d/*
51 alan@nazgul /etc/init.d $
52 --
53 Alan McKinnon
54 alan dot mckinnon at gmail dot com
55
56 --
57 gentoo-user@l.g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Need help with a regex Robin Atwood <robin.atwood@×××××××××.net>