Loading ...
Sorry, an error occurred while loading the content.

how to configure grep to be case insenitive in filenames

Expand Messages
  • Edward Wong
    Today I just find out an interesting issue... when I uses grep it treats the filenames as case sensitive, even when I include the -i flag....but when I do
    Message 1 of 12 , Mar 31 8:01 PM
    • 0 Attachment
      Today I just find out an interesting issue... when I uses grep it
      treats the filenames as case sensitive, even when I include the '-i'
      flag....but when I do grep in shell it works, because I configure
      cygwin to be case insensitive like dos.

      I'm now working with projects in dos with my co-workers....and
      sometimes they name the files in capital, and some don't. Also, I
      often need to grep generated files that the file names contain capital
      letters. Is there a way to configure grep in vim?

      PS: vimgrep works perfectly fine, but grep is faster.

      -- Ed
    • Edward Wong
      Dear all, would it be possible to configure :grep to search case-insensitive filenames? Any help will be great!
      Message 2 of 12 , Apr 2, 2006
      • 0 Attachment
        Dear all, would it be possible to configure :grep to search
        case-insensitive filenames? Any help will be great!

        On 4/1/06, Edward Wong <plwong@...> wrote:
        > Today I just find out an interesting issue... when I uses grep it
        > treats the filenames as case sensitive, even when I include the '-i'
        > flag....but when I do grep in shell it works, because I configure
        > cygwin to be case insensitive like dos.
        >
        > I'm now working with projects in dos with my co-workers....and
        > sometimes they name the files in capital, and some don't. Also, I
        > often need to grep generated files that the file names contain capital
        > letters. Is there a way to configure grep in vim?
        >
        > PS: vimgrep works perfectly fine, but grep is faster.
        >
        > -- Ed
        >
      • panshizhu@routon.com
        ... Are you sure you ve tried to set ignorecase in VIM? My grep works with mixed-case filename without problem. -- Sincerely Pan, Shizhu. ext: 2221
        Message 3 of 12 , Apr 2, 2006
        • 0 Attachment
          "Edward Wong" <plwong@...> wrote on 2006.04.03 13:36:38:
          > On 4/1/06, Edward Wong <plwong@...> wrote:
          > > Today I just find out an interesting issue... when I uses grep it
          > > treats the filenames as case sensitive, even when I include the '-i'
          > > flag....but when I do grep in shell it works, because I configure
          > > cygwin to be case insensitive like dos.
          > >
          > > I'm now working with projects in dos with my co-workers....and
          > > sometimes they name the files in capital, and some don't. Also, I
          > > often need to grep generated files that the file names contain capital
          > > letters. Is there a way to configure grep in vim?
          > >
          > > PS: vimgrep works perfectly fine, but grep is faster.
          > >
          > > -- Ed
          > >

          Are you sure you've tried to set ignorecase in VIM?

          My grep works with mixed-case filename without problem.

          --
          Sincerely
          Pan, Shizhu. ext: 2221
        • Edward Wong
          Ok I did a bit more testing. 1) I have a generated file named PDA.SS and PDA.S10 2) in .vimrc, set grepprg=grep -Hn 3) using cygwin as shell When I attempted
          Message 4 of 12 , Apr 3, 2006
          • 0 Attachment
            Ok I did a bit more testing.

            1) I have a generated file named PDA.SS and PDA.S10
            2) in .vimrc, set grepprg=grep\ -Hn
            3) using cygwin as shell

            When I attempted to search a variable in PDA.SS and PDA.S10 I realized
            the followings:

            grep -i variable PDA.SS -> works
            grep -i variable pda.ss -> works
            grep -i variable *.SS -> works
            grep -i variable PDA.* -> works
            grep -i variable *.ss -> doesn't work
            grep -i variable pda.* -> doesn't work
            grep -i variable *.* -> works

            grep -i variable PDA.S10 -> works
            grep -i variable pda.s10 -> works
            grep -i variable *.*10 -> works
            grep -i variable *.s10 -> doesn't work

            So it seems like :grep doesn't work as expected when I search file
            patterns that contain combination of "*" and "letters with wrong
            capital values". Basically it DOESN'T "ignorecase" when "*" presents.
            However, I often needs to grep sth like *.s*, or pda.* for example.

            Any idea?


            On 4/3/06, panshizhu@... <panshizhu@...> wrote:
            > "Edward Wong" <plwong@...> wrote on 2006.04.03 13:36:38:
            > > On 4/1/06, Edward Wong <plwong@...> wrote:
            > > > Today I just find out an interesting issue... when I uses grep it
            > > > treats the filenames as case sensitive, even when I include the '-i'
            > > > flag....but when I do grep in shell it works, because I configure
            > > > cygwin to be case insensitive like dos.
            > > >
            > > > I'm now working with projects in dos with my co-workers....and
            > > > sometimes they name the files in capital, and some don't. Also, I
            > > > often need to grep generated files that the file names contain capital
            > > > letters. Is there a way to configure grep in vim?
            > > >
            > > > PS: vimgrep works perfectly fine, but grep is faster.
            > > >
            > > > -- Ed
            > > >
            >
            > Are you sure you've tried to set ignorecase in VIM?
            >
            > My grep works with mixed-case filename without problem.
            >
            > --
            > Sincerely
            > Pan, Shizhu. ext: 2221
            >
            >
            >
            >
            >
            >
          • Chris Allen
            ... [snip] ... I might be wrong, but it seems to me that you re barking up the wrong tree, here. If you re using an external grep program then neither Vim nor
            Message 5 of 12 , Apr 3, 2006
            • 0 Attachment
              On 4/3/06, Edward Wong <plwong@...> wrote:
              > When I attempted to search a variable in PDA.SS and PDA.S10 I realized
              > the followings:
              [snip]
              > So it seems like :grep doesn't work as expected when I search file
              > patterns that contain combination of "*" and "letters with wrong
              > capital values". Basically it DOESN'T "ignorecase" when "*" presents.
              > However, I often needs to grep sth like *.s*, or pda.* for example.
              >
              > Any idea?

              I might be wrong, but it seems to me that you're barking up the wrong
              tree, here. If you're using an external grep program then neither Vim
              nor grep itself can influence which files it sees when you provide a
              wildcard argument. Expanding filename wildcards to proper name lists
              is the responsibility of the shell, not Vim nor grep. Your tests seem
              to indicate that you have a case-insensitive file system (i.e.
              providing a full name of the wrong case works), but not a
              case-insensitive shell (i.e. wildcards are matched in case-sensitive
              manner against the file names read from the file system).

              You might be able to work around this by using the find command and
              piping the resulting list of filenames to to grep. Alternately, your
              cygwin shell may include some configuration system which allows you to
              change the globbing behaviour. (Note that this paragraph is
              speculation.)

              HTH,
              Chris Allen
            • panshizhu@routon.com
              ... Have you tried that in your BASH prompt? My result are below: pansz-pc:~$ grep fad test1.txt adfadfaf pansz-pc:~$ grep fad test1.TXT adfadfaf pansz-pc:~$
              Message 6 of 12 , Apr 3, 2006
              • 0 Attachment
                "Edward Wong" <plwong@...> wrote on 2006.04.03 15:03:36:
                > Ok I did a bit more testing.
                >
                > 1) I have a generated file named PDA.SS and PDA.S10
                > 2) in .vimrc, set grepprg=grep\ -Hn
                > 3) using cygwin as shell
                >
                > When I attempted to search a variable in PDA.SS and PDA.S10 I realized
                > the followings:
                >
                > grep -i variable PDA.SS -> works
                > grep -i variable pda.ss -> works
                > grep -i variable *.SS -> works
                > grep -i variable PDA.* -> works
                > grep -i variable *.ss -> doesn't work
                > grep -i variable pda.* -> doesn't work
                > grep -i variable *.* -> works
                >
                > grep -i variable PDA.S10 -> works
                > grep -i variable pda.s10 -> works
                > grep -i variable *.*10 -> works
                > grep -i variable *.s10 -> doesn't work
                >
                > So it seems like :grep doesn't work as expected when I search file
                > patterns that contain combination of "*" and "letters with wrong
                > capital values". Basically it DOESN'T "ignorecase" when "*" presents.
                > However, I often needs to grep sth like *.s*, or pda.* for example.
                >
                > Any idea?

                Have you tried that in your BASH prompt? My result are below:

                pansz-pc:~$ grep fad test1.txt
                adfadfaf
                pansz-pc:~$ grep fad test1.TXT
                adfadfaf
                pansz-pc:~$ grep fad *.TXT
                grep: *.TXT: No such file or directory
                pansz-pc:~$ grep fad *.txt
                test1.txt:adfadfaf
                pansz-pc:~$

                Remember that the GREP itself cannot expand "*.txt", *.txt are expanded by
                BASH shell, NOT the GREP, so you may want to seek some help from your shell
                (in cygwin it should be /bin/bash or /bin/sh).

                --
                Sincerely
                Pan, Shizhu. ext: 2221
              • Yakov Lerner
                ... bash has nocaseglob option. Excerpt from man bash : nocaseglob If set, bash matches filenames in a case-insensitive fashion when performing pathname
                Message 7 of 12 , Apr 3, 2006
                • 0 Attachment
                  On 4/3/06, panshizhu@... <panshizhu@...> wrote:
                  > "Edward Wong" <plwong@...> wrote on 2006.04.03 15:03:36:
                  > > Ok I did a bit more testing.
                  > >
                  > > 1) I have a generated file named PDA.SS and PDA.S10
                  > > 2) in .vimrc, set grepprg=grep\ -Hn
                  > > 3) using cygwin as shell
                  > >
                  > > When I attempted to search a variable in PDA.SS and PDA.S10 I realized
                  > > the followings:
                  > >
                  > > grep -i variable PDA.SS -> works
                  > > grep -i variable pda.ss -> works
                  > > grep -i variable *.SS -> works
                  > > grep -i variable PDA.* -> works
                  > > grep -i variable *.ss -> doesn't work
                  > > grep -i variable pda.* -> doesn't work
                  > > grep -i variable *.* -> works
                  > >
                  > > grep -i variable PDA.S10 -> works
                  > > grep -i variable pda.s10 -> works
                  > > grep -i variable *.*10 -> works
                  > > grep -i variable *.s10 -> doesn't work
                  > >
                  > > So it seems like :grep doesn't work as expected when I search file
                  > > patterns that contain combination of "*" and "letters with wrong
                  > > capital values". Basically it DOESN'T "ignorecase" when "*" presents.
                  > > However, I often needs to grep sth like *.s*, or pda.* for example.
                  > >
                  > > Any idea?
                  >
                  > Have you tried that in your BASH prompt? My result are below:
                  >
                  > pansz-pc:~$ grep fad test1.txt
                  > adfadfaf
                  > pansz-pc:~$ grep fad test1.TXT
                  > adfadfaf
                  > pansz-pc:~$ grep fad *.TXT
                  > grep: *.TXT: No such file or directory
                  > pansz-pc:~$ grep fad *.txt
                  > test1.txt:adfadfaf
                  > pansz-pc:~$

                  bash has 'nocaseglob' option. Excerpt from 'man bash':
                  nocaseglob
                  If set, bash matches filenames in a case-insensitive
                  fashion when performing pathname expansion (see Pathname
                  Expansion above).
                  tcsh has similar option

                  Yakov
                • Edward Wong
                  ... Yes I did...that s why i found the result weird and posted this mail. When I do this in shell: $ grep var *.s10 PDA.S10:02000B2177_varBcode
                  Message 8 of 12 , Apr 4, 2006
                  • 0 Attachment
                    > >
                    > > Have you tried that in your BASH prompt? My result are below:

                    Yes I did...that's why i found the result weird and posted this mail.
                    When I do this in shell:

                    $ grep var *.s10
                    PDA.S10:02000B2177_varBcode
                    PDA.S10:02000B21B1_varBcodeIndex
                    PDA.S10:02000B2190_varBcodeName
                    PDA.S10:02000B21B9_varBcodeNote
                    PDA.S10:02000B21A9_varBcodeQty

                    but when I do this in vim
                    :grep var *.s10
                    :!grep -Hn var *.s10 2>&1| tee C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/VIeDE.tmp
                    (1 of 1): grep *.s10: No such file or directory

                    > bash has 'nocaseglob' option. Excerpt from 'man bash':

                    Yes...i already had:
                    shopt -s nocaseglob
                    in my .bashrc file.

                    I'm thinking if the shell that vim prompts have ever sourced the
                    .bashrc file since $HOME in vim is "d:\Programs\vim\vim70c" and $HOME
                    in cygwin is "d:/cygwin/home/Administrator". Can it be the problem? I
                    really dunno.... :(

                    --
                    Ed
                  • Edward Wong
                    ... Just tried setting $HOME to d:/cygwin/home/Administrator but :grep still returns No such file or directory
                    Message 9 of 12 , Apr 4, 2006
                    • 0 Attachment
                      > I'm thinking if the shell that vim prompts have ever sourced the
                      > .bashrc file since $HOME in vim is "d:\Programs\vim\vim70c" and $HOME
                      > in cygwin is "d:/cygwin/home/Administrator". Can it be the problem? I
                      > really dunno.... :(

                      Just tried setting $HOME to "d:/cygwin/home/Administrator" but :grep
                      still returns 'No such file or directory'
                    • David.Fishburn@sybase.com
                      I had to use: grep var --include=*.s10 * You might want to try that way. HTH, Dave ... From: Edward Wong [plwong@gmail.com] Sent: 04/04/2006 03:40 AM To:
                      Message 10 of 12 , Apr 4, 2006
                      • 0 Attachment
                        I had to use:
                        grep var --include=*.s10 *

                        You might want to try that way.

                        HTH,
                        Dave




                        ----- Original Message -----
                        From: "Edward Wong" [plwong@...]
                        Sent: 04/04/2006 03:40 AM
                        To: "Yakov Lerner" <iler.ml@...>
                        Cc: "panshizhu@..." <panshizhu@...>;vim@...
                        Subject: Re: how to configure grep to be case insenitive in filenames

                        > I'm thinking if the shell that vim prompts have ever sourced the
                        > .bashrc file since $HOME in vim is "d:\Programs\vim\vim70c" and $HOME
                        > in cygwin is "d:/cygwin/home/Administrator". Can it be the problem? I
                        > really dunno.... :(

                        Just tried setting $HOME to "d:/cygwin/home/Administrator" but :grep
                        still returns 'No such file or directory'
                      • Gary Johnson
                        ... Well, that s the problem then. Bash only reads the ~/.bashrc file if it is an interactive shell, which shells spawned from vim are not. You might try
                        Message 11 of 12 , Apr 4, 2006
                        • 0 Attachment
                          On 2006-04-04, Edward Wong <plwong@...> wrote:
                          > > >
                          > > > Have you tried that in your BASH prompt? My result are below:
                          >
                          > Yes I did...that's why i found the result weird and posted this mail.
                          > When I do this in shell:
                          >
                          > $ grep var *.s10
                          > PDA.S10:02000B2177_varBcode
                          > PDA.S10:02000B21B1_varBcodeIndex
                          > PDA.S10:02000B2190_varBcodeName
                          > PDA.S10:02000B21B9_varBcodeNote
                          > PDA.S10:02000B21A9_varBcodeQty
                          >
                          > but when I do this in vim
                          > :grep var *.s10
                          > :!grep -Hn var *.s10 2>&1| tee C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/VIeDE.tmp
                          > (1 of 1): grep *.s10: No such file or directory
                          >
                          > > bash has 'nocaseglob' option. Excerpt from 'man bash':
                          >
                          > Yes...i already had:
                          > shopt -s nocaseglob
                          > in my .bashrc file.

                          Well, that's the problem then. Bash only reads the ~/.bashrc file
                          if it is an interactive shell, which shells spawned from vim are
                          not.

                          You might try putting this in your ~/.vimrc:

                          let $BASH_ENV="~/.bashrc"

                          According to 'man bash',

                          When bash is started non-interactively, to run a shell script, for
                          example, it looks for the variable BASH_ENV in the environment, expands
                          its value if it appears there, and uses the expanded value as the name
                          of a file to read and execute. Bash behaves as if the following com-
                          mand were executed:
                          if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
                          but the value of the PATH variable is not used to search for the file
                          name.

                          HTH,
                          Gary

                          --
                          Gary Johnson | Agilent Technologies
                          garyjohn@... | Wireless Division
                          | Spokane, Washington, USA
                        • Edward Wong
                          Thanks Gary! That solves the problem. :)
                          Message 12 of 12 , Apr 5, 2006
                          • 0 Attachment
                            Thanks Gary! That solves the problem. :)

                            On 4/5/06, Gary Johnson <garyjohn@...> wrote:
                            > On 2006-04-04, Edward Wong <plwong@...> wrote:
                            > > > >
                            > > > > Have you tried that in your BASH prompt? My result are below:
                            > >
                            > > Yes I did...that's why i found the result weird and posted this mail.
                            > > When I do this in shell:
                            > >
                            > > $ grep var *.s10
                            > > PDA.S10:02000B2177_varBcode
                            > > PDA.S10:02000B21B1_varBcodeIndex
                            > > PDA.S10:02000B2190_varBcodeName
                            > > PDA.S10:02000B21B9_varBcodeNote
                            > > PDA.S10:02000B21A9_varBcodeQty
                            > >
                            > > but when I do this in vim
                            > > :grep var *.s10
                            > > :!grep -Hn var *.s10 2>&1| tee C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/VIeDE.tmp
                            > > (1 of 1): grep *.s10: No such file or directory
                            > >
                            > > > bash has 'nocaseglob' option. Excerpt from 'man bash':
                            > >
                            > > Yes...i already had:
                            > > shopt -s nocaseglob
                            > > in my .bashrc file.
                            >
                            > Well, that's the problem then. Bash only reads the ~/.bashrc file
                            > if it is an interactive shell, which shells spawned from vim are
                            > not.
                            >
                            > You might try putting this in your ~/.vimrc:
                            >
                            > let $BASH_ENV="~/.bashrc"
                            >
                            > According to 'man bash',
                            >
                            > When bash is started non-interactively, to run a shell script, for
                            > example, it looks for the variable BASH_ENV in the environment, expands
                            > its value if it appears there, and uses the expanded value as the name
                            > of a file to read and execute. Bash behaves as if the following com-
                            > mand were executed:
                            > if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
                            > but the value of the PATH variable is not used to search for the file
                            > name.
                            >
                            > HTH,
                            > Gary
                            >
                            > --
                            > Gary Johnson | Agilent Technologies
                            > garyjohn@... | Wireless Division
                            > | Spokane, Washington, USA
                            >
                          Your message has been successfully submitted and would be delivered to recipients shortly.