Search code examples
mysqlregexnotepad++phpbb3

Notepad++ regexp increase number


We've got an old PhPBB3 installation with a lot of posts in it. We've made a new installation which already contains new posts. What i want to do, is export the MySQL to XML from the old installation, reset post_id and topic_id to the following number of the new installation. We will put everything in 1 new category (import, 111).

            <column name="post_id">3</column>
        <column name="topic_id">3</column>

The new columns are running in 3000, lets say 3337. So what i need is every line that has

<column name="post_id">3</column>

Needs to get

<column name="post_id">3338</column>

Same goes for topic_id... How would one do this?


Solution

  • You can do it with Ruby, Python or Perl. Here's how it's done in Ruby:

    $ ruby -pi.bak -e '$_.gsub!(/(<column name="post_id">)(\d+)(<\/column>)/) { "#{$1}#{$2.to_i + 3000}#{$3}" }' file.xml
    

    Your file.xml will be edited in-place and the backup copy will be saved to file.xml.bak.