• Login
Community
  • Login

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

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 2 Posters 341 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.
  • W
    Watashi
    last edited by Watashi Sep 19, 2022, 2:21 AM Sep 19, 2022, 2:18 AM

    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.

    W 1 Reply Last reply Sep 19, 2022, 2:24 AM Reply Quote 0
    • W
      Watashi @Watashi
      last edited by Sep 19, 2022, 2:24 AM

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

      T 1 Reply Last reply Sep 19, 2022, 3:23 AM Reply Quote 0
      • T
        Terry R @Watashi
        last edited by Terry R Sep 19, 2022, 3:26 AM Sep 19, 2022, 3:23 AM

        @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

        W 1 Reply Last reply Sep 19, 2022, 3:55 AM Reply Quote 2
        • W
          Watashi @Terry R
          last edited by Sep 19, 2022, 3:55 AM

          @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!

          W 1 Reply Last reply Sep 19, 2022, 4:32 AM Reply Quote 0
          • W
            Watashi @Watashi
            last edited by Watashi Sep 19, 2022, 4:34 AM Sep 19, 2022, 4:32 AM

            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=" ?

            W 1 Reply Last reply Sep 19, 2022, 4:47 AM Reply Quote 0
            • W
              Watashi @Watashi
              last edited by Sep 19, 2022, 4:47 AM

              It worked, thanks a lot

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