Transform the style and order in a certain way.
-
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 -
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 ALLBut
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 that0.90
on the last line actually meant40.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.
-
@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 use10.0.0.0/8
split this into smaller blocks. -
@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.