[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: 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
|

Gary, I'm not sure if this is just playing around, or you're trying to
adress a real situation.  If it's the second, then you're doing two
opposing things.  First, you're calling ls with the -a switch which
specifically requests listing all hidden files and directories, 

>From the ls manpage:
-a will show you ALL the files in the directory, including hidden files

then your're trying to negate seeing those files and directories with
the grep command.  If you just do ls -l(lower case L), you'll get the
long listing without the hidden stuff.  If you do ls -1(number 1), then
you will only see one visible filename per line without size, owner,
date or permission info.

mike



Reply to: