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

writing a string after every nth character

Expand Messages
  • Praveen Jalem
    hi i want to write a string test after every 4th character on a line. e.g. 123456789111111 shud be changed to 1234test5678test9111test111 Any suggestion
    Message 1 of 6 , Dec 2, 2002
    • 0 Attachment
      hi
      i want to write a string 'test' after every 4th character on a line.
      e.g.
      '123456789111111' shud be changed to
      '1234test5678test9111test111'

      Any suggestion wud be appreciated.


      thanx
      praveen
    • BStrohhaecker@Hueller-Hille.com
      Von: Praveen Jalem [mailto:venkat.praveen@vwebsol.com] Gesendet: Montag, 2. Dezember 2002 12:55 ... Try :s/ (.... )/ 1test/g or :s/ (. {4} )/ 1test/g See
      Message 2 of 6 , Dec 2, 2002
      • 0 Attachment
        Von: Praveen Jalem [mailto:venkat.praveen@...]
        Gesendet: Montag, 2. Dezember 2002 12:55

        > hi
        > i want to write a string 'test' after every 4th character on a line.
        > e.g.
        > '123456789111111' shud be changed to
        > '1234test5678test9111test111'
        >
        > Any suggestion wud be appreciated.
        >

        Try ':s/\(....\)/\1test/g' or ':s/\(.\{4}\)/\1test/g'

        See ':h regex'

        Bernd
      • Jürgen Krämer
        Hi, ... Regards, Jürgen -- Jürgen Krämer Softwareentwicklung Habel GmbH
        Message 3 of 6 , Dec 2, 2002
        • 0 Attachment
          Hi,

          Praveen Jalem wrote:
          >
          > i want to write a string 'test' after every 4th character on a line.
          > e.g.
          > '123456789111111' shud be changed to
          > '1234test5678test9111test111'

          :%s/\d\{4\}/&test/g

          Regards,
          Jürgen

          --
          Jürgen Krämer Softwareentwicklung
          Habel GmbH mailto:jkraemer@...
          Hinteres Öschle 2 Tel: (0 74 61) 93 53 15
          78604 Rietheim-Weilheim Fax: (0 74 61) 93 53 99
        • Praveen Jalem
          It worked thanx -praveen
          Message 4 of 6 , Dec 2, 2002
          • 0 Attachment
            It worked


            thanx

            -praveen

            Brehm, Christian wrote:

            >try :%s/\(....\)/\1test/g
            >
            >-----Original Message-----
            >From: Praveen Jalem [mailto:venkat.praveen@...]
            >Sent: Montag, 2. Dezember 2002 12:55
            >To: vim@...
            >Subject: writing a string after every nth character
            >
            >
            >hi
            > i want to write a string 'test' after every 4th character on a line.
            >e.g.
            > '123456789111111' shud be changed to
            > '1234test5678test9111test111'
            >
            >Any suggestion wud be appreciated.
            >
            >
            >thanx
            >praveen
            >
            >
            >
          • Brett Pershing Stahlman
            ... From: Jürgen Krämer To: vim mailing list Sent: Monday, December 02, 2002 6:12 AM Subject: Re: writing a string after
            Message 5 of 6 , Dec 2, 2002
            • 0 Attachment
              ----- Original Message -----
              From: Jürgen Krämer <jkraemer@...>
              To: vim mailing list <vim@...>
              Sent: Monday, December 02, 2002 6:12 AM
              Subject: Re: writing a string after every nth character



              Hi,

              Praveen Jalem wrote:
              >
              > i want to write a string 'test' after every 4th character on a line.
              > e.g.
              > '123456789111111' shud be changed to
              > '1234test5678test9111test111'

              :%s/\d\{4\}/&test/g

              Unless I'm mistaken, there should not be a \ before the closing curly brace;
              also, if you may have non-digit characters on a line, you should use .
              instead of \d:

              :%s/.\{4}/&test/g

              Brett S.

              Regards,
              Jürgen

              --
              Jürgen Krämer Softwareentwicklung
              Habel GmbH mailto:jkraemer@...
              Hinteres Öschle 2 Tel: (0 74 61) 93 53 15
              78604 Rietheim-Weilheim Fax: (0 74 61) 93 53 99
            • Jürgen Krämer
              Hi, Brett Pershing Stahlman wrote: [quoting corrected] ... no, it s optional. Regards, Jürgen -- Jürgen Krämer
              Message 6 of 6 , Dec 2, 2002
              • 0 Attachment
                Hi,

                Brett Pershing Stahlman wrote:

                [quoting corrected]

                > ----- Original Message -----
                > From: Jürgen Krämer <jkraemer@...>
                >
                >> :%s/\d\{4\}/&test/g
                >
                > Unless I'm mistaken, there should not be a \ before the closing curly brace;

                no, it's optional.

                Regards,
                Jürgen


                --
                Jürgen Krämer Softwareentwicklung
                Habel GmbH mailto:jkraemer@...
                Hinteres Öschle 2 Tel: (0 74 61) 93 53 15
                78604 Rietheim-Weilheim Fax: (0 74 61) 93 53 99
              Your message has been successfully submitted and would be delivered to recipients shortly.