bash, grep, and regular expressions
Hi All,
I'm pretty much a noob at regular expressions but have been studying
them lately using Jeffrey Friedl's book Mastering Regular Expressions
2nd ed.. I've run across something that has me puzzled. Here's what it is.
Now before you flame me this is done strictly as an exercise in regular
expressions.
I have ls aliased to ls -al. What I've been attempting to do with grep
and regular expressions is list only non-hidden directories and/or
files. I am unable to come up with an expression that will elimate
hidden files and return non-hidden files at the same time.
ls -al | grep -v ' \.\<[a-zA-Z0-9].*\>' # returns everything
ls | grep -e '\<[^.][[:alnum:]]' # returns everything
ls | grep -e '\<[.][[:alnum:]]' # returns an empty set
I've tried many more expressions than these but none of them have worked
so far and the first one works on a Solaris 9 machine with a bash shell.
I also cannot write a back reference that uses parenthesis. I copied
examples right out of Friedl's book and they won't work either. I get a
"invalid back reference" error every time I try.
Anyone have any insight into this? I'm running sarge with a 2.6.9
kernel on one Debian box and a 2.6.10 kernel on another, and all
packages are the very latest packages available in sarge on both boxes.
TIA
Gary
Reply to:
- Follow-Ups:
- Re: bash, grep, and regular expressions
- From: Glenn English <ghe@slsware.com>
- Re: bash, grep, and regular expressions
- From: "Todd A. Jacobs" <nospam@codegnome.org>
- RE: bash, grep, and regular expressions
- From: "Mike Kuhar" <mikewk147@comcast.net>
- Re: bash, grep, and regular expressions
- From: Matt Zagrabelny <mzagrabe@d.umn.edu>
- Re: bash, grep, and regular expressions
- From: Justin Guerin <jguerin@cso.atmel.com>
- Re: bash, grep, and regular expressions
- From: Pigeon <jah.pigeon@ukonline.co.uk>