From caffebab2edcbe8a7934b3b7dad4d132c7ccd8a7 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Fri, 15 Jan 2021 17:09:25 +0000 Subject: [PATCH] Add parent-urls --- parent-urls | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 parent-urls diff --git a/parent-urls b/parent-urls new file mode 100755 index 0000000..6e961cb --- /dev/null +++ b/parent-urls @@ -0,0 +1,14 @@ +#!/bin/bash +prog0='BEGIN { FS="/"; OFS="/" }' # Set the field separators +prog1='{ print }' # Print the input URL (if desired) +prog2='/\/$/ { --NF }' # Remove the trailing blank field if the URL ends with a slash +prog3='{ for (i = NF; i > 3; --i) { --NF; print $0 OFS; } }' # One by one, remove the last path component, print remaining fields + +prog="${prog0} " +if [[ "$1" == '--with-original' ]] +then + prog="${prog}${prog1} " +fi +prog="${prog}${prog2} ${prog3}" + +exec awk "${prog}"