From a9a03d3a00eddf0573c364f98349b1b0f6d661c5 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Sat, 19 Mar 2022 22:39:04 +0000 Subject: [PATCH] Add urlsort --- urlsort | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 urlsort diff --git a/urlsort b/urlsort new file mode 100755 index 0000000..6830aeb --- /dev/null +++ b/urlsort @@ -0,0 +1,3 @@ +#!/bin/bash +# Reads a list of URLs from stdin, sorts by domain (in reverse label order), protocol, port, auth, and remainder of the URL. +python3 -c 'import re, sys'$'\n''for line in sys.stdin:'$'\n'' line = line.strip()'$'\n'' m = re.search(r"^(?P[^/]*)://(?P[^/@]*@)?(?P[^/]*?)(?P:\d+)?(?P(?:/.*)?$)", line)'$'\n'' reversedomain = ".".join(reversed(m["domain"].split(".")))'$'\n'' print(line, reversedomain, m["protocol"], m["port"] or "", m["auth"] or "", m["rest"] or "")' | sort -k2 | cut -d' ' -f1