Another way to do it (this is Perl, after all):

  cat filname.txt | perl -p -e "$_=quotemeta($_)" | xargs ....

or just

  cat filname.txt | perl -p -e "$_=quotemeta" | xargs ....

You don't need the -i switch since you are not in-place editing a file.

Patrick McCabe


----- Original Message -----
From: Liz Burke-Scovill <kethry at winternet.com>
To: <tclug-list at mn-linux.org>
Sent: Tuesday, January 16, 2001 1:13 PM
Subject: Re: [TCLUG] perl regex question


> On Tue, 16 Jan 2001, Austad, Jay wrote:
>
> > Ok, I have this shell script that pipes some stuff to xargs.  Some of
the
> > stuff has lone single quotes in it and breaks the pipe to xargs because
of
> > an unmatched quote error.  So to fix this, I do something like:
> >
> > cat filname.txt | perl -pi -e "s/\'/\\\'/g" | xargs ....
>
> perl -pi -e "s/(\W)/\\$1/g" should do the trick - \W looks for all non
> alphanumeric characters - putting it in parenthesis turns it into a
> segment for backreferencing, $1 is the backreference variable
>
>  >
> > How can I modify that perl statement so it will take single quotes,
double
> > quotes, greater/less than signs, question marks, and asterisks, and
replace
> > them with a backslash and then themselves?
> >
> > * would be \*
> > ? would be \?
> > " would be \"
> > and so on.
> >
> > I don't want to have a bunch of -e statements in my little perl command.
> >
> > Jay
> > _______________________________________________
> > tclug-list mailing list
> > tclug-list at mn-linux.org
> > https://mailman.mn-linux.org/mailman/listinfo/tclug-list
> >
>
> --
> Imagination is intelligence having fun...
> e-mail:  kethry at winternet.com
> URL:  http://WWW.winternet.com/~kethry/index.html
>
> _______________________________________________
> tclug-list mailing list
> tclug-list at mn-linux.org
> https://mailman.mn-linux.org/mailman/listinfo/tclug-list
>