UX Headache – Joining Lines in a Text File

A part of me seriously wants to be involved in UX. I constantly find problems with just about every UI in which I interface. This one is beautiful, but it is lacking. This one is ugly, but works. Maybe it’s why I love PowerShell; it’s always the same no matter what I’m working with. It’s probably also why I wish every website on the planet was written with APIs first. What an amazing world, if I could do everything using PowerShell: check the bank, register children for school, order Chipotle, and make appointments at the doctor, the dentist, the eye doctor, the auto shop, etc. The list is endless.

Anyway, back to the topic here. I’ve often considered buying a new domain and pointing out awful, real-world experiences of my own until someone comes along, realizes I get it, and employs me to stop all the awful interfaces… at least for that company. Us humans, living in this digital world, are constantly subjected to awful-looking, unhelpful, and inconsistent interfaces that have become a requirement in our lives. If I request that your site show me 100 rows at a time, then it’s not likely I’m going to change my mind when I click into one record and then go back out to the row view again. And if I do want to change it, guess what, that’s on me. I could go on for days.

The company responsible for those, two paragraphs is the reason I’m writing today. I was sent a list of 100 or 200 CIDR ranges. No problem, I’ll just copy and paste them into that one box on the website set to accept both single IPs and CIDR ranges. Nope. That caused an error. It was unable to parse it, and so now it was my job to enter them one at a time!? Well, it would’ve been had I not known PowerShell. Seriously, someone somewhere might be doing that. Copy and paste, or select and drag, or whatever other option was left. Whichever method, it would be much slower than what I did. So, today’s post is both me venting a little of my pent-up UX frustration and providing a quick resolution for anyone in this same situation, that didn’t automatically think PowerShell themselves. You see, the interface would take a comma-separated list, it just couldn’t handle a line-delimited list–if that’s even what that’s called. Maybe new-line-delimited; I don’t know for sure.

Here’s what I had (after removing the public IP addresses):

10.138.80.0/22
10.138.87.160/27
10.138.91.160/27
10.138.129.0/29
10.139.33.96/28
10.139.38.0/27
10.224.1.32/27
10.224.41.128/25
10.224.43.0/24
10.224.73.0/25
10.228.21.192/27
10.120.1.0/27
10.128.1.32/27
10.128.11.64/26
10.128.29.0/24
10.128.205.128/26
10.130.66.0/25
10.152.7.160/27
10.152.12.0/24
10.152.13.0/24
10.152.14.0/24
10.152.15.0/27
10.156.20.0/28
10.156.20.16/28
10.156.20.32/27
10.156.20.96/27
10.156.24.0/22
10.156.28.128/26
10.156.29.0/24
10.156.30.0/24
10.156.31.0/24
10.156.32.0/24
10.156.33.0/24
10.156.34.0/24
10.156.35.0/24
10.156.36.0/24
10.156.42.0/24
10.156.43.0/24
10.160.20.0/25
10.161.43.0/25
10.161.43.128/25
10.161.44.0/22
10.161.48.0/22
10.162.2.0/27
10.166.9.0/24
10.192.237.0/26
10.192.238.0/24
10.192.255.0/25
10.193.120.0/25
10.193.120.128/25
10.193.121.0/25
10.193.121.128/25
10.193.122.0/25
10.193.122.128/25
10.193.123.0/25
10.193.123.128/25
10.193.124.0/25
10.193.124.128/25
10.193.125.0/25
10.208.17.0/24
10.208.21.0/24
10.224.21.0/25
10.224.40.0/24
10.224.61.192/26
10.224.71.32/27
10.224.71.160/27
10.224.72.192/27
10.224.74.0/23
10.224.78.0/24
10.224.81.0/25
10.224.81.128/25
10.224.82.64/26
10.224.83.0/24
10.224.100.0/22
10.224.104.0/22
10.224.108.0/22
10.224.112.0/22
10.224.116.0/22
10.224.120.0/22
10.224.124.0/22
10.224.128.0/23
10.224.130.0/23
10.224.132.0/23
10.224.134.0/23
10.224.136.0/23
10.224.138.0/23
10.224.140.0/23
10.224.142.0/23
10.224.148.0/22
10.226.3.0/26
10.229.16.0/23
10.230.12.128/25
10.140.76.0/24
10.140.78.0/28
10.140.102.0/24
10.140.103.0/24
10.140.113.0/24
10.140.138.0/24
10.140.139.0/26
10.120.1.32/28
10.128.167.32/27
10.192.178.64/26
10.194.3.128/25
10.224.5.128/26
10.224.42.0/25
10.224.76.0/24
10.224.77.0/24
10.224.79.0/24
10.224.96.0/22
10.140.100.0/24
10.140.101.0/24
10.140.104.0/24
10.140.105.0/24
10.140.106.0/24
10.193.120.0/21
10.130.169.0/24
10.224.9.0/24

Let’s save this file to my computer as C:\Users\tommymaynard\Documents\CIDR.txt. Now, let’s see how many entries we’re working with. What kind of time might I save?

$Path = 'C:\Users\tommymaynard\Documents\CIDR.txt'
(Get-Content -Path $Path).Count
117

We’re working with 117 entries, or rather, 116 commas. Yeah, I’m not moving those over one by one; I don’t have the kind of time during my day. Enter PowerShell. To begin testing, I chose a smaller subset of the CIDR ranges. When I was happy with that, which was practically immediately, I added the -join operator.

Get-Content -Path $Path | Select-Object -First 5
10.138.80.0/22
10.138.87.160/27
10.138.91.160/27
10.138.129.0/29
10.139.33.96/28
(Get-Content -Path $Path | Select-Object -First 5) -join ','
10.138.80.0/22,10.138.87.160/27,10.138.91.160/27,10.138.129.0/29,10.139.33.96/28

Once I had this, I only had two things left to do. One, test to see if the company’s UI accepted comma-separated entries like this, and two, if it did, then join all 117 addresses with a comma in between each, and carry on with my day. That’s three things. Well, four if you count writing up this post after work. The UI did accept things that way, and so I ran the below command, pasted it in the box, saved everything, and reported back to my customer that it was set and done, as requested. Next.

(Get-Content -Path $Path) -join ',' | Set-Clipboard

Leave a Reply

Your email address will not be published. Required fields are marked *