The little things give you away... A collection of various small helper stuff
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

20 lignes
782 B

  1. #!/bin/bash
  2. if [[ "$1" == '--help' || "$1" == '-h' ]]
  3. then
  4. echo "Usage: parent-urls [--with-original]" >&2
  5. echo "Take URLs on stdin, remove path components one by one and print the resulting URLs on stdout." >&2
  6. echo "If --with-original is given, the input URL is printed before the parents." >&2
  7. fi
  8. prog=''
  9. prog+='BEGIN { FS="/"; OFS="/" }' # Set the field separators
  10. if [[ "$1" == '--with-original' ]]
  11. then
  12. prog+='{ print }' # Print the input URL (if desired)
  13. fi
  14. prog+='/[?#]/ { sub(/[?#].*/, "") }' # Remove query and fragment if present
  15. prog+='/\/$/ { --NF }' # Remove the trailing blank field if the URL ends with a slash
  16. prog+='{ for (i = NF; i > 3; --i) { --NF; print $0 OFS; } }' # One by one, remove the last path component, print remaining fields
  17. exec awk "${prog}"