Skip to content

Instantly share code, notes, and snippets.

@0xtavi
Last active December 1, 2022 16:55
Show Gist options
  • Save 0xtavi/597eda0184cbc0aa3d02fe08edeed15c to your computer and use it in GitHub Desktop.
Save 0xtavi/597eda0184cbc0aa3d02fe08edeed15c to your computer and use it in GitHub Desktop.
Shell script for extracting unique directories from a file containing urls line by line
#!/bin/sh
# Inspired from https://twitter.com/rez0__
# Usage ./unique_directories.sh urls.txt
rm unique_urls.txt > /dev/null
cat $1 | rev | cut -d/ -f2- | rev | sort -u | anew unique_urls.txt > /dev/null
for i in {1..10}; do cat unique_urls.txt | rev | cut -d/ -f2- | rev | sort -u | anew unique_urls.txt > /dev/null; done
sed -i "" "s/$/\//g" unique_urls.txt
sed -i "" "/^\/$/d" unique_urls.txt
sed -e "/\/\/$/d" unique_urls.txt | grep -Ev "(:/|://)$" | sort -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment