Menu

Moving tabbed text

Humphr3y
2015-05-11
2015-05-11
  • Humphr3y

    Humphr3y - 2015-05-11

    Hello everyone,

    I hope I can properly express what I need.

    I have to manage (on a daily basis, more or less) some files provided from an external source. It's the dump from a database table and is obviously organized in tabbed text - each tab has its name IN EVERY LINE. Something like this:

    userid: id (tab) username: name (tab) joined_on: date (tab) fav_food: food (tab) fav_band: band (tab) fav_color: color (tab) fav_game: game

    What I am trying to do (without the possibility of doing it in the source file, or in the original db) is rearrange the tabbed text. I need to

    1) SELECT ALL the "fav_band:" occurrences in the files
    2) MOVE THEM at the end of each respective line.

    Is there a way to do it using NPP? I tried to record a macro to (find using regex)-(cut)-(move cursor at the end of the line)-(paste) but it just doesn't seem to work properly when I choose "Run Multiple Times".

    Thank you for any answer!

     

    Last edit: Humphr3y 2015-05-11
  • THEVENOT Guy

    THEVENOT Guy - 2015-05-11

    Hello Murphr3y,

    This work is, typically, the kind of search-replacement that you can perform, very easily, with regular expressions :-))

    Here is, below, the different steps to follow :

    • Open your file, in Notepad++

    • If necessary, move back to the very beginning of your file ( CTRL + Origin )

    • Open the Replace dialog ( CTRL + H )

    • Type (\tfav_band.+?)(\t.+) in the Find what : zone

    • Type \2\1 in the Replace with : zone

    • Select the Regular expression search mode ( IMPORTANT )

    • Uncheck, if necessary, the . matches newline option ( IMPORTANT )

    • Finally, click on the Replace All button

    Et voilà !!


    Some explanations :

    • The search regex tries to match a tabulation character( \x09 ), followed by the string fav_band, followed, itself, by any non empty range of characters, until the first other tabulation character, and, finally, followed by any non empty range of characters till the end of the current line

    • The first tabulation, and the string fav_band, till the next tabulation character, excluded, are surrounded by round brackets, to create a group 1, that will be used, in the replacement part, with the syntax \1

    • The first tabulation character, after the string fav_band, and all characters till the end of the line, are also surrounded by round brackets to get a group 2

    • In the replacement part, the two groups, are just rewritten, in the inverse order : \2\1


    I hope that this post will help you a bit !

    Best Regards

    guy038

    Remainder :

    • The regex A.*Z matches the longest range of characters, empty or not, between the uppercase letters A and Z

    • The regex A.*?Z matches the shortest range of characters, empty or not, between the uppercase letters A and Z

     

    Last edit: THEVENOT Guy 2015-05-11
  • Humphr3y

    Humphr3y - 2015-05-11

    It
    works
    like
    a
    CHARM

    :)))

    Thank you so much!