Community
    • Login

    Transform the style and order in a certain way.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 147 Views
    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.
    • sabry fargS
      sabry farg
      last edited by PeterJones

      I have a text file that contains IPs

      but they are placed randomly

      Example

      40.90.128.128/2840.90.128.224/28
      40.90.129.0/2740.90.129.32/2840.90.129.64/2640.90.129.128/2640.90.129.224/27
      

      I want it to be like this

      40.90.128.128/28
      40.90.128.224/28
      40.90.129.0/27
      40.90.129.32/28
      40.90.129.64/26
      40.90.129.128/26
      0.90.129.224/27
      

      —

      moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @sabry farg
        last edited by PeterJones

        @sabry-farg ,

        Assuming what you pasted is what you really have, with no separation between one CIDR and the next IP:

        If you can guarantee that, for you, the /## will always be two digits, it’s doable:
        FIND /\d\d\K
        REPLACE \r\n
        SEARCH MODE: Regular Expression
        REPLACE ALL

        But

        10.0.0.0/246.7.8.9/8
        

        could be parsed validly as either

        10.0.0.0/24
        6.7.8.9/8
        

        or as

        10.0.0.0/2
        46.7.8.9/8
        

        So if you have no additional restriction on the CIDR, what you are asking for is impossible

        –
        My answer also assumes that 0.90 on the last line actually meant 40.90 like on all the other lines.

        And a similar regex could be derived to the one I showed if the rule was “all IP start with 40”, or similar. There just must be a rule, or it’s impossible.

        mkupperM 1 Reply Last reply Reply Quote 4
        • mkupperM
          mkupper @PeterJones
          last edited by

          @PeterJones and @sabry-farg - most of the time the number of bits, which is the value after the / is two digits and can range from 10 to 32. However, the values 0 to 9 are possible with /8 being fairly common as those are class A networks with 16-million IP addresses in the blocks.

          One of the standard private IP address blocks is at 10.0.0.0/8 though most organizations that use 10.0.0.0/8 split this into smaller blocks.

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

            @mkupper ,

            My point wasn’t to get into the details of IPv4 and CIDR, but to show that, as asked, the problem is unanswerable without more detail, even when the person answering does know at least a little about the problem domain.

            When asking for help with data transformation, people need to provide enough information about the requirements for someone to be able to answer them, without requiring the answerer to know generically about the kind of data they are using, and without requiring that they make guesses as to hidden/implied restrictions which make the difference between “easy” and “impossible”, as I pointed out in my examples.

            1 Reply Last reply Reply Quote 3
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors