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

Re: [PBML] substituting text in files wholesale

Expand Messages
  • Boga Srinivas
    ... you can try redirecting it. Not sure whether this works. -- Boga Srinivas System Engineer Yahoo! Ph : +91 8030516347 Mob : +91 9900859469 ... %% Although
    Message 1 of 8 , Nov 30, 2006
    • 0 Attachment
      Santosh Sugur wrote:
      >
      > Thanks.
      > Leslie I couldn't get that working either.
      >
      > Srinivas, since I have to replace a large number of files I am doing the
      > following:
      > $find . -type f | xargs sed -e 's/\*/\$var/g
      >
      > Now I get all the output on the screen with the right substitution,
      > but the
      > files have not changes. Infact I had not used sed for the same reason. Can
      > you tell me how to make sed write back to the files.
      >
      > -Santosh
      >
      > On 11/30/06, Boga Srinivas <bseenu@...
      > <mailto:bseenu%40yahoo-inc.com>> wrote:
      > >
      > > leslie.polzer@... <mailto:leslie.polzer%40gmx.net>
      > <leslie.polzer%40gmx.net> wrote:
      > > >
      > > > On Wed, Nov 29, 2006 at 08:42:03PM +0530, Santosh Sugur wrote:
      > > >
      > > > > Hi Guys,
      > > > >
      > > > > I want to substitute a certain string (/*/) in a number of files
      > > > > which are again perl source files with a variable name instead
      > of the
      > > > > asterix.
      > > > >
      > > > > I am doing the following which I got after googling a while.
      > > > >
      > > > > $find . -type f -exec perl -lp -i -e "s/\/\*\//$var/g" {} \;
      > > > >
      > > > > what happens is that since $var holds nothing, the asterix is
      > > > > substitited by nothing, so I get // as the new string instead of
      > > > > /$var/ I tried escaping the $ in $var but that didn't help. I also
      > > > > tried using single quotes but that too didn't work. Can some one
      > show
      > > > > me how to go about this?
      > > > From perlre:
      > > >
      > > > "You cannot include a literal $ or @ within a \Q sequence. An
      > unescaped
      > > > $ or @ interpolates the corresponding variable, while escaping will
      > > > cause the literal string \$ to be matched. You'll need to write
      > > > something like m/\Quser\E\@\Qhost/."
      > > >
      > > > Maybe that solves your problem.
      > > >
      > > > Leslie
      > > >
      > > > --
      > > > gpg --keyserver pgp.mit.edu --recv-keys DD4EBF83
      > > > http://nic-nac-project.de/~skypher/
      > <http://nic-nac-project.de/%7Eskypher/>
      > > > <http://nic-nac-project.de/%7Eskypher/
      > <http://nic-nac-project.de/%7Eskypher/><http://nic-nac-project.de/~skypher/
      > <http://nic-nac-project.de/%7Eskypher/>>
      > > >
      > > >
      > > > [Non-text portions of this message have been removed]
      > > >
      > > >
      > > Try out this
      > >
      > > -bash-2.05b$ cat test.pl
      > > #!/usr/bin/perl
      > >
      > > $var = "hello this is *";
      > >
      > > -bash-2.05b$ sed -e 's/\*/\$var/g' test.pl
      > > #!/usr/bin/perl
      > >
      > > $var = "hello this is $var";
      > >
      > > --
      > >
      > > Boga Srinivas
      > > System Engineer
      > > Yahoo!
      > > Ph : +91 8030516347
      > > Mob : +91 9900859469
      > >
      > > ---------------------------------------------------------
      > >
      > > %%
      > > Although the Perl Slogan is There's More Than One Way to Do It, I
      > hesitate
      > > to make 10 ways to do something. :-)
      > > -- Larry Wall in <9695@...
      > <mailto:9695%40jpl-devvax.JPL.NASA.GOV><9695%40jpl-devvax.JPL.NASA.GOV>
      > > >
      > > %%
      > >
      > >
      > >
      >
      > [Non-text portions of this message have been removed]
      >
      >
      you can try redirecting it.

      Not sure whether this works.



      --

      Boga Srinivas
      System Engineer
      Yahoo!
      Ph : +91 8030516347
      Mob : +91 9900859469


      ---------------------------------------------------------

      %%
      Although the Perl Slogan is There's More Than One Way to Do It, I hesitate
      to make 10 ways to do something. :-)
      -- Larry Wall in <9695@...>
      %%
    • Santosh Sugur
      Thanks everyone. I shall give all these a try and save my best one :) Thanks again.
      Message 2 of 8 , Dec 7, 2006
      • 0 Attachment
        Thanks everyone. I shall give all these a try and save my best one :)
        Thanks again.

        On 12/1/06, deepak2id <deepak2id@...> wrote:
        > Hi Santosh,
        > below one liner should solve your purpose. Try this.
        >
        > $find . -type f | xargs perl -pi -e 's/\*/\$var/g'
        >
        > Regards,
        > Deepak Sahoo
        >
        >
        > --- In perl-beginner@yahoogroups.com, "Santosh Sugur"
        > <santosh.sugur@...> wrote:
        > >
        > > Thanks.
        > > Leslie I couldn't get that working either.
        > >
        > > Srinivas, since I have to replace a large number of files I am
        > doing the
        > > following:
        > > $find . -type f | xargs sed -e 's/\*/\$var/g
        > >
        > > Now I get all the output on the screen with the right substitution,
        > but the
        > > files have not changes. Infact I had not used sed for the same
        > reason. Can
        > > you tell me how to make sed write back to the files.
        > >
        > > -Santosh
        > >
        > > On 11/30/06, Boga Srinivas <bseenu@...> wrote:
        > > >
        > > > leslie.polzer@... <leslie.polzer%40gmx.net> wrote:
        > > > >
        > > > > On Wed, Nov 29, 2006 at 08:42:03PM +0530, Santosh Sugur wrote:
        > > > >
        > > > > > Hi Guys,
        > > > > >
        > > > > > I want to substitute a certain string (/*/) in a number of
        > files
        > > > > > which are again perl source files with a variable name
        > instead of the
        > > > > > asterix.
        > > > > >
        > > > > > I am doing the following which I got after googling a while.
        > > > > >
        > > > > > $find . -type f -exec perl -lp -i -e "s/\/\*\//$var/g" {} \;
        > > > > >
        > > > > > what happens is that since $var holds nothing, the asterix is
        > > > > > substitited by nothing, so I get // as the new string instead
        > of
        > > > > > /$var/ I tried escaping the $ in $var but that didn't help. I
        > also
        > > > > > tried using single quotes but that too didn't work. Can some
        > one show
        > > > > > me how to go about this?
        > > > > From perlre:
        > > > >
        > > > > "You cannot include a literal $ or @ within a \Q sequence. An
        > unescaped
        > > > > $ or @ interpolates the corresponding variable, while escaping
        > will
        > > > > cause the literal string \$ to be matched. You'll need to write
        > > > > something like m/\Quser\E\@\Qhost/."
        > > > >
        > > > > Maybe that solves your problem.
        > > > >
        > > > > Leslie
        > > > >
        > > > > --
        > > > > gpg --keyserver pgp.mit.edu --recv-keys DD4EBF83
        > > > > http://nic-nac-project.de/~skypher/
        > > > > <http://nic-nac-project.de/%7Eskypher/<http://nic-nac-
        > project.de/~skypher/>
        > > > >
        > > > >
        > > > > [Non-text portions of this message have been removed]
        > > > >
        > > > >
        > > > Try out this
        > > >
        > > > -bash-2.05b$ cat test.pl
        > > > #!/usr/bin/perl
        > > >
        > > > $var = "hello this is *";
        > > >
        > > > -bash-2.05b$ sed -e 's/\*/\$var/g' test.pl
        > > > #!/usr/bin/perl
        > > >
        > > > $var = "hello this is $var";
        > > >
        > > > --
        > > >
        > > > Boga Srinivas
        > > > System Engineer
        > > > Yahoo!
        > > > Ph : +91 8030516347
        > > > Mob : +91 9900859469
        > > >
        > > > ---------------------------------------------------------
        > > >
        > > > %%
        > > > Although the Perl Slogan is There's More Than One Way to Do It, I
        > hesitate
        > > > to make 10 ways to do something. :-)
        > > > -- Larry Wall in <9695@...<9695%40jpl-devvax.JPL.NASA.GOV>
        > > > >
        > > > %%
        > > >
        > > >
        > > >
        > >
        > >
        > > [Non-text portions of this message have been removed]
        > >
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.