Browse Source

Add urlsort

master
JustAnotherArchivist 2 years ago
parent
commit
a9a03d3a00
1 changed files with 3 additions and 0 deletions
  1. +3
    -0
      urlsort

+ 3
- 0
urlsort View File

@@ -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<protocol>[^/]*)://(?P<auth>[^/@]*@)?(?P<domain>[^/]*?)(?P<port>:\d+)?(?P<rest>(?:/.*)?$)", 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

Loading…
Cancel
Save