Split Field Into Two Fields

  • I am very new to Notepad++ so not sure if I’m wording this right, but I have a txt file where each record is a specific length. I have an Address “field” that is 100 character wide (padded with spaces) that starts at character 56… If the street address is two lines, both lines are in that field, separated by a tilde. I need the part after the tiled moved so that I basically have two 50 character fields. So, to give an example, this

    In Care of John Doe~1000 John Street Hobbs NM 88240

    would become

    In Care of John Doe 1000 John Street Hobbs NM 88420

  • @Kasey-Gonzales

    I think you might be a “victim” of the “markdown” syntax used on this site in trying to show your “before” and “after” text.

    Maybe you are trying to say this:

                                                           In Care of John Doe~1000 John Street Hobbs NM 88240                                                 |
                                                           In Care of John Doe                               1000 John Street Hobbs NM 88240                   |

    I added a “ruler line” with every 10 columns called out; also a vertical bar at the end of what I think would be your “before” and “after” lines.

    I really don’t know if this is correct or not. You probably have non-blank data to the left of column 56. And maybe to the right.

    Anyway if you want to show your before and after data better, here’s the key: Indent each line with 4 spaces when you paste into this site. Then it will become what is known as a “code block” (the black box above).

  • Yes, that’s more what my before and after is supposed to look like…thanks!

    And yes, there is non-blank data to the left and right.

  • Hello, @kasey-gonzales,

    Thanks to Scott, we can figure out your problem, much better ! So, as your address field is 100 characters wide, in case of a two-lines address, each part, before and after the tilde character ( ~ ), have a maximum of 50 characters and, of course, a minimum of 1 character.

    Thus, given, for instance, the original text, below ( By convention, I’m using digits in the first part address, before the ~ and upper-case letters, in the second part, after the ~ character, both between 1 and 50 characters long )

                                                           In Care of John Doe~1000 John Street Hobbs NM 88240

    I would propose two steps :

    • A FIRST normal OR regex search / replacement, which adds 50 space characters, in front of the ~ symbol :
    SEARCH  :~
    REPLACE :                                                  ~
    • A SECOND regex search / replacement, right after, which deletes any consecutive range of space characters, between position 106 and the ~ symbol :
    SEARCH  :(?-s)^(.{105}) +~
    REPLACE :\1

    Notes :

    • Copy/paste, in the Replace dialog, each zone, selecting text AFTER the colon character

    • In the second search regex ^(.{105}) +~, there is a space character, before the + symbol

    • Select the Regular expression mode

    • In the second replacement regex, we just re-write the group 1 ( the first 105 characters of each line )

    • These two S/R preserves any text which is before column 56 , and after the second part of the address field

    Then, after these two consecutive regex S/R, you should obtain the text, below, with the second part address moved to column 106 :

                                                           1                                                 A
                                                           1                                                 ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ
                                                           In Care of John Doe                               1000 John Street Hobbs NM 88240


    • If your text may contain some tabulation characters, just change them by the appropriate number of space characters, using the Edit - Blank Operations - TAB to Space menu option !

    • If your text may contain other ~ characters, located outside the address field, just tell me and we’ll slightly change the first search !

    Best Regards,


Log in to reply