Re: Bash Pattern Matching Syntax

From: Will Maier (willmaier_at_ml1.net)
Date: 10/16/05

  • Next message: Brian A. Seklecki: "ng_one2many v.s. AFT (NIC Fault Tolerance/Fail Over/Redundancy Revisited)"
    Date: Sat, 15 Oct 2005 18:07:06 -0500
    To: freebsd-questions@freebsd.org
    
    

    On Sat, Oct 15, 2005 at 03:37:11PM -0700, Drew Tomlinson wrote:
    > I want to list the files in a directory that end in ".jpg"
    > irregardless of case. Thus after reading the bash man page, it
    > seems I should be able to issue a command something along the
    > lines of "ls [*.[JjPpGg]]" or "ls *.[JjPpGg]" but neither of
    > these work and return a "No such file or directory" message. I've
    > also tried various ways of escaping the '*' and '." but that
    > didn't help either. However "ls *[JjPpGg]" does work by listing
    > the files. However I want to match the "." before "jpg" as well.
    > What is the correct syntax for what I'm trying to do?

    The square brackets define a range of characters; [a-z] includes all
    lowercase alphabetic characters between 'a' and 'z' and will match
    _only one character from that range_ in a given string.
        
        [a-z] matches 'b'
        [a-z] matches 'z'
        [a-z] doesn't match 'all'
        [a-z] doesn't match '1'

    Your first attempt, [*.[JjPpGg]], has an extra pair of brackets.
    Secondly, it (like your second attempt) defines a range that would
    match only one character, JjPpGg:
        
        [JjPpGg] matches 'j'
        [JjPpGg] matches 'G'
        [JjPpGg] doesn't match 'JPG'
        [JjPpGg] doesn't match 'jpg'

    You need to break your patterns up; what you're looking for is a
    pattern of three characters, with 'J' or 'j' in the first position,
    'P' or 'p' in the second, and 'G' or 'g' in the third. That entire
    pattern should be prepended by a string of any characters (*) and a
    period (.).

    Here are some examples to demonstrate what I've written above; they
    conclude with a pattern that will match the files you're looking
    for.

        sh-3.00$ ls
        a all test.JPG test.jpg
        sh-3.00$ ls [a-z]
        a
        sh-3.00$ ls [all]
        a
        sh-3.00$ ls *.[JjPpGg]
        ls: *.[JjPpGg]: No such file or directory
        sh-3.00$ ls *.[Jj][Pp][Gg]
        test.JPG test.jpg

    -- 
    o--------------------------{ Will Maier }--------------------------o
    | jabber:..wcmaier@jabber.ccc.de | email:..........wcmaier@ml1.net |
    | \.........wcmaier@cae.wisc.edu | \..........wcmaier@cae.wisc.edu |
    *------------------[ BSD Unix: Live Free or Die ]------------------*
    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
    

  • Next message: Brian A. Seklecki: "ng_one2many v.s. AFT (NIC Fault Tolerance/Fail Over/Redundancy Revisited)"

    Relevant Pages

    • Re: Set App Priority
      ... string and then terminates" ... gives then parameters to use to modify the START command ... below) /F:OFF Disable file and directory name completion characters ... no special characters between the two quote characters, ...
      (microsoft.public.windowsxp.customize)
    • Re: Extract letters and numbers from string
      ... While the Like operator patterns cannot begin to compare to those from a Regular Expression parser, they are still quite flexible and you can still get quite complex with them. ... What the pattern does is insure the text in the variable Value is made up of nothing but digits. ... The exclamation mark inside the square brackets says to look for characters NOT in the range 0 through 9, the asterisks on either side says to look for this non-digit anywhere within the text contained in the Value variable. ... > Public Function AlphaNumeralsAs String ...
      (microsoft.public.excel.programming)
    • Re: Extract letters and numbers from string
      ... While the Like operator patterns cannot begin to compare to those from a ... exclamation mark inside the square brackets says to look for characters NOT ... the Like pattern tests can all be included into a single pattern test... ... Public Function AlphaNumeralsAs String ...
      (microsoft.public.excel.programming)
    • Re: how to calculate number of characters in argument?
      ... and would like to have available a command for calculating the ... the use of ASCII test within CJK text). ... to 0) for typesetting 9 half-width characters (which are I believe set ... It works by first stripping off everything before the decimal point, then feeding the remaining string of characters to a recursive macro that creates a \numexpr of the form: ...
      (comp.text.tex)
    • Re: RegEx: How to ignore the number of whitespaces?
      ... matching character sequences in strings. ... what are the limitations of the "arbitrary Unicode characters?" ... Exactly one of them must be found in the string, ... Certain subsequences of a pattern may be marked as optional. ...
      (microsoft.public.dotnet.framework)