[sf-lug] regex: how to match any one to four character word in a file
eric at ericwalstad.com
Wed Dec 10 09:27:38 PST 2008
On Wed, Dec 10, 2008 at 8:37 AM, jim <jim at well.com> wrote:
> i've given up on the online tutorials.
Sometimes I have to give up on regex and go with what I'm more
proficient at. So, while I'm not answering your question in terms of
regex, here's something that might work for you in Python and can be
used in a command pipeline. If nothing else, it's a simple example of
how to handle pipelining. I suspect this is nothing new to you but
I'm hoping it's helpful to other listeners...
----- words.py -----
for line in sys.stdin:
for field in line.split():
if len(field) > 0 and len(field) <= 4:
ewalstad at sawarna:~$ cat foo
can do wrds on one line too
ewalstad at sawarna:~$ cat foo | ./words.py
ewalstad at sawarna:~$ cat foo | ./words.py | grep "^a.*"
More information about the sf-lug