How do I combined each 2 lines with a :



  • So I have alot of lines that look like this
    a999999a
    Matt48947
    b999999b
    unicornlove101010
    smile123
    Mattp1
    p1looser
    raventehpanda

    And want to turn it to something like this
    a999999a:Matt48947
    b999999b:unicornlove101010
    smile123:Mattp1
    p1looser:raventehpanda

    How do I go about that? Also how do I delete duplicate lines without textfx? because I can’t download it / install it.



  • Hello, @fouad-tbz, and All,

    Your first task is very easy to achieve :

    • If you have to do this S/R, in a particular area of tour text, do a normal selection, first

    • Open the Replace dialog ( Ctrl + H )

    • If a previous selections exist, turn on the In selection option

    • Else, just ticked the Wrap around option

    • Select the Regular expression search mode

    SEARCH (?-s)(^.+)\R(.+)

    REPLACE \1:\2

    Click on the Replace All button

    Et voilà !


    Regarding deleting duplicate lines, two solutions are possible :

    • If you don’t mind sorting your text, first, ( Edit > Line Operations > Sort Lines Lexicographically Ascending ) use the following regex S/R :

    SEARCH (?-s)(^.+\R)\1+

    REPLACE \1

    which will delete all duplicate consecutive lines of your sorted list

    • Now, if you prefer to preserve the present order of your list, use the regex S/R, below :

    SEARCH ^(?-s)(^.+\R)(?s)(?=.*\R\1)

    REPLACE Leave EMPTY

    which will delete all duplicate lines, keeping, only, the last duplicate lines !


    Notes :

    • In all regexes, the (?-s) modifier, means that the dot special character matches any single standard character, only

    • In the third regex, the (?s) syntax means that, afterwards, the . can match, absolutely, any single character, even EOL ones

    • In the first regex, the (^.+) and (.+) part stand for a complete line, from column 1, without its EOL characters

    • In the last two regeges, the (^.+\R) part matches a complete line, from column 1, with its EOL characters

    • All areas between parentheses define a group, numbered 1, 2 and so on…, which can be re-used, either, in the search or replacement part, with the syntax \1, \2 and so on…

    • The + quantifier ( or {1,} ) represents any non-null repetition of the previous character or group

    • The * quantifier ( or {0,} ) represents any repetition, ( even none ) of the previous character or group

    • Finally, the \R syntax matches any king of EOL characters( line-break ), whatever the file ( Windows, Unix or Mac )

    Best Regards,

    guy038

    P.S. :

    For further information about regular expressions, refer to the link below :

    https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation/1



  • @Fouad-tbz You can also use Macro for this. First, place the caret on the first line, in front of the first word. Start the macro recording and type the following keys:

    • End
    • :
    • Delete
    • Down arrow
    • Home

    Stop the recording. Play the macro (1 time or repeat).


Log in to reply