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

Re: [PBML] Appending a character to each line in a file

Expand Messages
  • Dave Gray
    ... That s a good question, I m not exactly sure WHY it does that, but I can tell you how to fix it - take out the /g pattern modifier, or unambiguify the $ by
    Message 1 of 9 , Apr 7, 2004
      Walt Weaver wrote:
      > Okay, I'm trying to use "perl -pi -e 's/$/;/g' <filename>" to append
      > a semicolon to the end of each line in a file in linux.
      >
      > But, perl wants to insert a semicolon at the end AND the start of
      > each line.

      That's a good question, I'm not exactly sure WHY it does that, but I can
      tell you how to fix it - take out the /g pattern modifier, or
      unambiguify the $ by firmly anchoring it to the last character:

      perl -pi -e 's/(.)$/$1;/g' <filename>

      I guess perl is getting confused by the lonely $.

      Cheers,
      Dave
    • Emanuel G Calso
      That would put a ; at the beggining of each line - i don t know why. But this would worked in a shell, anyway: perl -pi -e s/ n/; n/g v--v ...
      Message 2 of 9 , Apr 8, 2004
        That would put a ";" at the beggining of each line - i don't know why.
        But this would worked in a shell, anyway:
        "perl -pi -e 's/\n/;\n/g' <filename>"

        v--v
        On Thursday 2004 April 08 09:43, Dave Gray wrote:
        > Walt Weaver wrote:
        > > Okay, I'm trying to use "perl -pi -e 's/$/;/g' <filename>" to append
        > > a semicolon to the end of each line in a file in linux.
        > >
        > > But, perl wants to insert a semicolon at the end AND the start of
        > > each line.
        >
        > That's a good question, I'm not exactly sure WHY it does that, but I can
        > tell you how to fix it - take out the /g pattern modifier, or
        > unambiguify the $ by firmly anchoring it to the last character:
        >
        > perl -pi -e 's/(.)$/$1;/g' <filename>
        >
        > I guess perl is getting confused by the lonely $.
        >
        > Cheers,
        > Dave
        --
        eman calso
        http://www.bloodpet.tk/
        "Dying is a very dull, dreary affair. And my advice to you is to have
        nothing whatever to do with it."
        -- W. Somerset Maugham
      • Walt Weaver
        ... can ... Yup, getting rid of the g does the trick. Thanks for the info! --Walt
        Message 3 of 9 , Apr 8, 2004
          --- In perl-beginner@yahoogroups.com, Dave Gray <yahoogroups@d...> wrote:
          > Walt Weaver wrote:
          > > Okay, I'm trying to use "perl -pi -e 's/$/;/g' <filename>" to append
          > > a semicolon to the end of each line in a file in linux.
          > >
          > > But, perl wants to insert a semicolon at the end AND the start of
          > > each line.
          >
          > That's a good question, I'm not exactly sure WHY it does that, but I
          can
          > tell you how to fix it - take out the /g pattern modifier, or
          > unambiguify the $ by firmly anchoring it to the last character:
          >
          > perl -pi -e 's/(.)$/$1;/g' <filename>
          >
          > I guess perl is getting confused by the lonely $.
          >
          > Cheers,
          > Dave

          Yup, getting rid of the g does the trick.

          Thanks for the info!

          --Walt
        Your message has been successfully submitted and would be delivered to recipients shortly.