The little things give you away... A collection of various small helper stuff
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

22 рядки
775 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. prog0='BEGIN { FS="/"; OFS="/" }' # Set the field separators
  9. prog1='{ print }' # Print the input URL (if desired)
  10. prog2='/\/$/ { --NF }' # Remove the trailing blank field if the URL ends with a slash
  11. prog3='{ for (i = NF; i > 3; --i) { --NF; print $0 OFS; } }' # One by one, remove the last path component, print remaining fields
  12. prog="${prog0} "
  13. if [[ "$1" == '--with-original' ]]
  14. then
  15. prog="${prog}${prog1} "
  16. fi
  17. prog="${prog}${prog2} ${prog3}"
  18. exec awk "${prog}"