Community
    • Login

    Delete columns using ++ notepad

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 2.1k Views 3 Watching
    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.
    • favio rodiF Offline
      favio rodi
      last edited by

      Hello everyone, I appeal to you to help me, I have a file of approximately 35k, in the following format

      col1:col2:col3:col4:col5

      My question is if you can combine column by column? as follows:

      col1:col2
      col1:col3
      col1:col4
      col1:col5

      col2:col3
      col2:col4
      col2:col5

      col3:col4
      col3:col5

      col4:col5

      How can I do this using notepad?
      thanks

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • Scott SumnerS Offline
        Scott Sumner @favio rodi
        last edited by

        @favio-rodi

        It might be possible. First, though, curious how that kind of data manipulation is useful. Can you explain the real-world example?

        1 Reply Last reply Reply Quote 0
        • PeterJonesP Offline
          PeterJones
          last edited by PeterJones

          @favio-rodi,

          It appears to me that you are trying to list all the combinations of those 5 columns, taken 2 at a time, preserving original column order. Personally, for data combinatorics, I would use a full programming language (I would use Perl; many others would use Python or Lua or some other personal favorite language; a benefit of the latter two is that there are NPP plugins available which embed copies of the programming language in NPP, and allow you direct access to the currently-open files in Notepad++, rather than making you manually deal with the file i/o portion of the code).

          Assuming it’s literally 5 columns, you can do it rather straightforwardly using a regular expression:

          • Find what: ^([^:\r\n]+):([^:\r\n]+):([^:\r\n]+):([^:\r\n]+):([^:\r\n]+)$
          • Replace with: $1:$2\r\n$1:$3\r\n$1:$4\r\n$1:$5\r\n\r\n$2:$3\r\n$2:$4\r\n$2:$5\r\n\r\n$3:$4\r\n$3:$5\r\n\r\n$4:$5\r\n
          • Search Mode = Regular Expression

          This finds 5 groups separated by colons, all on a single line; it replaces those with windows-newline(CRLF)-separated combinations columns.

          If you wanted an expression that would handle pairs of columns taken from 6 original columns, you would need one extra term in the Find What, and you would need nCr = C(n,r) = C(6,2) = 6!/4!/2! = 15 terms in the Replace With. If you want to be able to handle an arbitrary n number of columns, you would probably want to do it in a programming language – or at least generate the regular expression in a program (because manually generating the Find what and Replace with was tedious with 5 columns, and would get rather annoying pretty quickly beyond that.

          With the expression above, if I start with

          col1:col2:col3:col4:col5
          one:two:doesnt match because five 'columns' split across:
          multiple:lines
          a:b:c:d:e
          

          I end up with

          col1:col2
          col1:col3
          col1:col4
          col1:col5

          col2:col3
          col2:col4
          col2:col5

          col3:col4
          col3:col5

          col4:col5

          one:two:doesnt match because five ‘columns’ split across:
          multiple:lines
          a:b
          a:c
          a:d
          a:e

          b:c
          b:d
          b:e

          c:d
          c:e

          d:e

          favio rodiF 1 Reply Last reply Reply Quote 5
          • favio rodiF Offline
            favio rodi @PeterJones
            last edited by

            @PeterJones , thank you very much Mr. PeterJones

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors