Community
    • Login

    How to replace a specific term adding/replacing a incremented number?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 340 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • WatashiW
      Watashi
      last edited by Watashi

      Hi everyone, here I’m again to ask for some help:

      I need to replace the part that says:

      <item id="23224"
      

      Document data:

      	<item id="23224" name="Renault Kwid Zen 1.0 12v SCe (Flex)">
      		<set name="car_type" val="HATCH" />
      		<set name="year" val="2019" />
      		<set name="color" val="white" />
      		<set name="bodykit" val="none" />
      		<set name="damage" val="engine" />
      		<set name="km" val="20000" />
      		<set name="weight" val="1100" />
      		<set name="doors" val="5" />
      	</item>
      	<item id="23225" name="Renault Sandero Expression 1.0 12V SCe (Flex)">
      		<set name="car_type" val="HATCH" />
      		<set name="year" val="2019" />
      		<set name="color" val="white" />
      		<set name="bodykit" val="none" />
      		<set name="damage" val="none" />
      		<set name="km" val="30000" />
      		<set name="weight" val="1200" />
      		<set name="doors" val="5" />
      	</item>
      	<item id="23226" name="Fiat Mobi Evo Like 1.0 (Flex)">
      		<set name="car_type" val="HATCH" />
      		<set name="year" val="2019" />
      		<set name="color" val="gray" />
      		<set name="bodykit" val="none" />
      		<set name="damage" val="wheel" />
      		<set name="km" val="40000" />
      		<set name="weight" val="900" />
      		<set name="doors" val="5" />
      	</item>
      

      I have a document with 4000 lines to replace, as you can see, I can’t increment the number using column feature, the first values are ok, but there’s new data between the old, so I need to update the sequency

      Thanks in advance.

      WatashiW 1 Reply Last reply Reply Quote 0
      • WatashiW
        Watashi @Watashi
        last edited by

        Basically, I need to replace to same thing, just to update number sequency…

        Terry RT 1 Reply Last reply Reply Quote 0
        • Terry RT
          Terry R @Watashi
          last edited by Terry R

          @Watashi said in How to replace a specific term adding/replacing a incremented number?:

          Basically, I need to replace to same thing, just to update number sequency…

          It would appear from the 3 example records you show that each record is 10 lines long. If EVERY record is 10 lines long you can use the column editor and introduce an increasing number with the repeat set to 10. That would mean the same number is repeated for each of the lines in 1 record. The next record would start with a new number which is repeated for that record.

          Once those numbers are inserted into the left column you would use a regular expression to replace the current record number with the new number. On the lines where item id= doesn’t exist no replacement occurs. Then finally remove those numbers at the start of the line.

          That would seem the simplest way of doing it, albeit it takes a few more steps.

          An alternative is to combine all lines in each record into 1 line by using a special delimiter so those lines can be recreated later. Then again using column editor insert ascending numbers with repeat as 1. Once the number has been changed out then recreate the lines by swapping the delimiter for real line feeds and carriage returns.

          Terry

          WatashiW 1 Reply Last reply Reply Quote 2
          • WatashiW
            Watashi @Terry R
            last edited by

            @Terry-R said in How to replace a specific term adding/replacing a incremented number?:

            @Watashi said in How to replace a specific term adding/replacing a incremented number?:

            Basically, I need to replace to same thing, just to update number sequency…

            It would appear from the 3 example records you show that each record is 10 lines long. If EVERY record is 10 lines long you can use the column editor and introduce an increasing number with the repeat set to 10. That would mean the same number is repeated for each of the lines in 1 record. The next record would start with a new number which is repeated for that record.

            Once those numbers are inserted into the left column you would use a regular expression to replace the current record number with the new number. On the lines where item id= doesn’t exist no replacement occurs. Then finally remove those numbers at the start of the line.

            That would seem the simplest way of doing it, albeit it takes a few more steps.

            An alternative is to combine all lines in each record into 1 line by using a special delimiter so those lines can be recreated later. Then again using column editor insert ascending numbers with repeat as 1. Once the number has been changed out then recreate the lines by swapping the delimiter for real line feeds and carriage returns.

            Terry

            Seems that some records has more than 10 lines, but I’ll try, thanks!

            WatashiW 1 Reply Last reply Reply Quote 0
            • WatashiW
              Watashi @Watashi
              last edited by Watashi

              managed how to add sequential number at begin of the line, then I used [0-9]+ <set to remove extra numbers, so now is like this:

              23224	<item id="23224" name="Renault Kwid Zen 1.0 12v SCe (Flex)">
              		<set name="car_type" val="HATCH" />
              		<set name="year" val="2019" />
              		<set name="color" val="white" />
              		<set name="bodykit" val="none" />
              		<set name="damage" val="engine" />
              		<set name="km" val="20000" />
              		<set name="weight" val="1100" />
              		<set name="doors" val="5" />
              	</item>
              23225	<item id="23225" name="Renault Sandero Expression 1.0 12V SCe (Flex)">
              		<set name="car_type" val="HATCH" />
              		<set name="year" val="2019" />
              		<set name="color" val="white" />
              		<set name="bodykit" val="none" />
              		<set name="damage" val="none" />
              		<set name="km" val="30000" />
              		<set name="weight" val="1200" />
              		<set name="doors" val="5" />
              	</item>
              23226	<item id="23226" name="Fiat Mobi Evo Like 1.0 (Flex)">
              		<set name="car_type" val="HATCH" />
              		<set name="year" val="2019" />
              		<set name="color" val="gray" />
              		<set name="bodykit" val="none" />
              		<set name="damage" val="wheel" />
              		<set name="km" val="40000" />
              		<set name="weight" val="900" />
              		<set name="doors" val="5" />
              	</item>
              

              If I got it right, now I need regex to add something different of “<item id=” before the numbers, then use <item id=“[0-9]+” to replace by nothing, and at tha last, replace that “something” back to <item id=" ?

              WatashiW 1 Reply Last reply Reply Quote 0
              • WatashiW
                Watashi @Watashi
                last edited by

                It worked, thanks a lot

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors