----- Original Message ----- From: "Gary Johnson" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, November 18, 2006 2:40 AM
Subject: Re: grep.vim support


On 2006-11-09, Stahlman Family <[EMAIL PROTECTED]> wrote:

I use several different solutions for different scenarios. When a basic or
extended regex will do, I use mingw grep, invoked from a Bash script on all
of the files in my current "project". ...

                                                       Note that this Bash
script passes the pattern to grep on stdin, which protects it from any sort
of DOS or Bash shell escaping. This means I can type the pattern on the Vim
command line *EXACTLY* as I wish it to be seen by grep. The importance of
this cannot be overstated...

How are you doing this?  Are you using the -f option to grep to pass
the pattern from a file?  Otherwise, I don't see how you can avoid
having the shell see the pattern at some point.

I use
   cexpr system('mygrep.sh ' . <more stuff here ...> , pattern)

to get the pattern to my shell script on stdin and have the stdout from the 
shell script turned into a quickfix list.

The script reads the pattern from stdin with
   read -r patt
(The -r option to read builtin ensures that backslashes in the pattern are not 
treated as escape char.)

There are two ways to invoke grep without compromising the pattern:

1) expand pattern within double quotes
   grep -nH$gropt "$patt" "[EMAIL PROTECTED]"
(Note that the double quotes protect the pattern from pathname expansion, word 
splitting, etc... after parameter expansion.)

2) Pass pattern to grep on stdin via a here-document (stdin specified via -f-)
   grep -nH$gropt -f- "[EMAIL PROTECTED]" <<-HERE
       $patt
   HERE


I've always found enclosing the pattern in single quotes to be
sufficient protection when using Cygwin or Unix.

Originally, my Bash script used xargs to invoke grep, but I found that I
could achieve significant execution time savings by running grep on
"chunks" of 50-100 files at a time (actual number is an option to the Bash
script), rather than running it once per file as was being done with xargs.

But xargs doesn't give its command argument one file at a time--it
gives the command as many files as it can, limited by ARG_MAX and
LINE_MAX.

Yes. David Thompson pointed that out to me earlier. I felt a bit silly that I hadn't read xargs' man page more before attempting to work around a perceived limitation. (Ironically, at one time I had a multiline sed script grouping the arguments into chunks to be passed to xargs in a pipeline!) Perhaps that is what Larry Wall would call "false hubris"...

Brett S.


In the following example,

   $ ls | xarsg echo | wc
          3     360    4719

xargs executed echo three times with an average of 120 file name
arguments per execution.

Regards,
Gary

--
Gary Johnson                 | Agilent Technologies
[EMAIL PROTECTED]     | Wireless Division
                            | Spokane, Washington, USA


Reply via email to