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

Re: bash, grep, and regular expressions



Mike wrote:


Freddy Freeloader wrote:

Adam Garside wrote:

On Fri, Feb 18, 2005 at 03:58:42AM -0800, Freddy Freeloader wrote:
[snip]

I can't write an expression that parses the beginning of the filename column.



How about:

ls -la | awk '$8 ~ /^[^.]/{print}'
which returns all non-hidden files and directories.

-- asg



I'm sorry to say, that it returns everthing. It's as if the output of ls -al is printed directly to the screen. Don't feel bad though this has happened to me every time I've tried something, and to everyone else too, and I've had 8 or 10 people give me examples that they say works on their machines.

That's why I'm here on this list. I can't figure this out. It's like there's a bug in this, but I'm not willing to write it off to that as yet because I don't have that much experience with regular expressions.


How about:

ls -la | awk '{ if (substr($9,0,1) != ".") {print $9}}'

-mike


I know you're not going to want to hear this, but....

That turned out one word which isn't the name of any file or directory, and about 100 blank lines on either side of it.

I'm really beginning to think that there is a bug in my systems. I've been given several expressions that should be able to accomplish this, and I've personally worked on this for hours writing every variation I could come up with, and still I can't find anything that works on my machines. I've had at least a half-dozen people give me expressions that work on their personal machines that won't work on mine.

Thanks for your effort.



Reply to: