Re: bash, grep, and regular expressions
Matt Zagrabelny wrote:
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.
the last sentence above is a little misleading. ls does that by default.
so examples of what you want are:
.bashrc
something.cc
bin/
examples of what you dont want are:
.ssh/
.gnome2/
is this correct?
-matt zagrabelny
What I'm trying to do is return something like this
test.txt
bin/
rather than
.ssh/
test.txt
bin/
.bashrc
I have found some regular expressions that will filter out specific
files and extensions, but not something that will filter exclusively on
the . that signfies a hidden file or directory. The best luck I've had
in filtering is to do something like this:
ls -al | grep -e ^d | grep -e '[.][a-z]'
This will filter to return directories only with the first grep command
and then the second grep will return only hidden directories that begin
with small caps. However, where I run into problems is:
ls -al | grep -e ^d | grep -e '[^.][a-z]'
You would think this would return only directories that begin with
anything except . and begin with lower case letters. This however is not
true. It returns all directories and ignores case altogether.
Reply to: