On Sat, 4 Jan 2003 [EMAIL PROTECTED] wrote:

> Hi Lawson!
>
> On Sat, 04 Jan 2003, [EMAIL PROTECTED] wrote:
>
> > This also seems to work:
> >
> > find -name 'Makefile'|xargs -i perl -pi -e 's/-Werror//g' {}
>
> First off thank you very much! It worked fine.
> But now I still want to understand it ;)
>
> What I dont understand is the:
>
> 1) "-i perl" option
>       man page says:
>       --replace[=replace-str], -i[replace-str]
>               Replace occurences of replace-str  in  the  initial
>               arguments  with  names  read  from  standard input.
>               Also, unquoted blanks do not  terminate  arguments.
>               If  replace-str  is  omitted,  it  defaults to "{}"
>               (like for `find -exec').  Implies -x and -l 1.

the first -i is an option to xargs, so it will run the command
perl -pi -e 's/-Werror//g' {}
once for each filename find found, with the filename substituted for the
{}
I should have said find -type f -name ... in case you had any
directories named Makefile.
>
>    As I understand this it calls perl and executes the regexp on a file.
>       The explanation of the -i option in man page of xargs and that it
>       calls perl doesnt fit together in my understanding.

calls perl once for each file.
>
> 2) "-pi" option
>       "-p" runs the "program" first through the C preprocessor, right? But
>       what for?

No, that is -P
-p couses perl to execute the command on each line of each named file.
I'll attach an excerpt from man perlrun that describes it.
>       
>       "-i" means that the file is edited in-place? What does that mean?

The changed file replaces the original file.
>
> 3) What is the {} for?
>
The default --replace-string for xargs.
>
> Thank you very much,
> Axel
>

--
---oops---
       -p   causes Perl to assume the following loop around your
            program, which makes it iterate over filename argu-
            ments somewhat like sed:

              LINE:
                while (<>) {
                    ...             # your program goes here
                } continue {
                    print or die "-p destination: $!\n";
                }

            If a file named by an argument cannot be opened for
            some reason, Perl warns you about it, and moves on to
            the next file.  Note that the lines are printed auto-
            matically.  An error occurring during printing is
            treated as fatal.  To suppress printing use the -n
            switch.  A -p overrides a -n switch.

            `BEGIN' and `END' blocks may be used to capture con-
            trol before or after the implicit loop, just as in
            awk.

       -P   causes your program to be run through the C prepro-
            cessor before compilation by Perl.  (Because both
            comments and cpp directives begin with the # charac-
            ter, you should avoid starting comments with any
            words recognized by the C preprocessor such as "if",

Reply via email to