The little things give you away... A collection of various small helper stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

15 lines
483 B

  1. #!/bin/bash
  2. prog0='BEGIN { FS="/"; OFS="/" }' # Set the field separators
  3. prog1='{ print }' # Print the input URL (if desired)
  4. prog2='/\/$/ { --NF }' # Remove the trailing blank field if the URL ends with a slash
  5. prog3='{ for (i = NF; i > 3; --i) { --NF; print $0 OFS; } }' # One by one, remove the last path component, print remaining fields
  6. prog="${prog0} "
  7. if [[ "$1" == '--with-original' ]]
  8. then
  9. prog="${prog}${prog1} "
  10. fi
  11. prog="${prog}${prog2} ${prog3}"
  12. exec awk "${prog}"