Re: bash, grep, and regular expressions

From: Peter Simpson (peter_at_petethetree.com)
Date: 02/18/05

  • Next message: Clive Menzies: "Re: Konqueror: clicked file parameter ... how ???"
    To: debian-user@lists.debian.org
    Date: Fri, 18 Feb 2005 16:59:01 +0000
    
    

    On Friday 18 Feb 2005 16:38, Freddy Freeloader wrote:
    > 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.

    Your search matches any string in the line that contains something that is not
    a period, followed by a lower case letter.

    This matches pretty much anything.

    What you want to do is limit this somewhat!

    A better idea would be to match two numbers followed by a space, followed by
    your letter.

    What works for me is:

    ls -al | grep -e ^d | grep -e ':[0-9][0-9] [^\.][a-zA-Z]'

    HTH.

    -- 
    To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
    

  • Next message: Clive Menzies: "Re: Konqueror: clicked file parameter ... how ???"

    Relevant Pages

    • Re: bash, grep, and regular expressions
      ... Matt Zagrabelny wrote: ... I have found some regular expressions that will filter out specific ... that signfies a hidden file or directory. ... This will filter to return directories only with the first grep command ...
      (Debian-User)
    • Re: Hidden File
      ... Unfortunately I downloaded it straight to my Desktop without changing the file name first, so I now have a hidden file (.filter) on there that I don't know how to get rid of. ...
      (uk.comp.sys.mac)
    • Re: Hidden File
      ... so I now have a hidden file on there that ... Open a Terminal window. ... Type 'rm .filter dot-filter'. ...
      (uk.comp.sys.mac)
    • Re: Hidden File
      ... Unfortunately I downloaded it straight to my Desktop without changing the file name first, so I now have a hidden file (.filter) on there that I don't know how to get rid of. ...
      (uk.comp.sys.mac)