Find the answer to your Linux question:
Results 1 to 6 of 6
Hi all, I am working on a code base which has lot of source code files. So, i end up using ack ( ack 1.94 -- better than grep, a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Location
    Chennai, India
    Posts
    28

    How to tell ack tool to ignore case under REGEX


    Hi all,

    I am working on a code base which has lot of source code files. So, i end up using ack (ack 1.94 -- better than grep, a source code search tool for programmers) tool for searching the filename i need to open.

    My source code is arranged in the following manner

    /home
    /home/X/sample.c
    /home/X/Sample.c
    /home/X/sAmPle.c
    ...
    ...
    ...

    Now i need to list the files whose name is "sample" ignoring the case. When i look at the man page of ACK command i can see that ignore case can't be used with -g option.

    -g REGEX
    Print files where the relative path + filename matches REGEX. This option is a convenience shortcut for -f -G REGEX.

    The options -i, -w, -v, and -Q do not apply to this REGEX.
    I am not comfortable with REGEX. Can some one help me in forming the REGEX so that i can list all the files with name "sample" regardless of case.

    Thanks.

  2. #2
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    699
    if it is true regex, you could do

    [sS][aA][mM][pP][lL][eE]\.[cC]

    but I haven't used that tool, so I can't confirm.
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

  3. #3
    Just Joined!
    Join Date
    Jul 2008
    Posts
    93
    Reading the man.page for ack I find the following switch:

    -i, --ignore-case Ignore case distinctions in PATTERN

    This ought to solve your problem without needing a REGEX.

    Try the command:

    ack -i sample.c

  4. #4
    Just Joined!
    Join Date
    Feb 2009
    Location
    Chennai, India
    Posts
    28
    @meton: Thanks your solution works

    @clowenstein: I have already looked into man page and it was clearly mentioned ignore case can't be used with -g option

    Extract from man page
    -g REGEX
    Print files where the relative path + filename matches REGEX. This option is a convenience shortcut for -f -G REGEX.

    The options -i, -w, -v, and -Q do not apply to this REGEX.

  5. #5
    Just Joined!
    Join Date
    Jul 2008
    Posts
    93
    My point was that for the example you gave, you don't need to use a REGEX at all.

    If your real problem is more complicated than that simple example, perhaps you need to state it better.

  6. #6
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    699
    Quote Originally Posted by cbalu View Post
    @meton: Thanks your solution works

    @clowenstein: I have already looked into man page and it was clearly mentioned ignore case can't be used with -g option

    Extract from man page
    no problem, glad to help.
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •