Advertisement
darsinqauros

Obter apenas o domínio da URL

Sep 29th, 2011
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.11 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. arquivo="$HOME/teste.txt"
  4.  
  5. cat - >> "$arquivo" <<EOF
  6. http://www.unix.com/shell-programming-scripting/36565-exit-shell-script.html
  7. http://www.blaa.com.br/ble/bli.htm
  8. http://www.claa.com.br/cle/cli.htm
  9. http://www.sub1.dlaa.com/dle/dli.htm
  10. http://www.sub2.ela.co.uk/ele/eli.htm
  11. http://flaa.com/fle
  12. http://suba.glaa.com/gle
  13. http://sub.sub2.hlaa.com/hle
  14. http://sub.sub2.ilaa.net.jp/ile
  15. http://sub2.sub3.jlaa.net/jle
  16. http://sub.dominio23.com
  17. EOF
  18.  
  19. sed -e 's/\(\([^\/]*\)\/\)\{3\}.*/\2/' -e '/\([a-zA-Z]\)\{3\}$/{s/\(.*\.\)\([a-zA-Z0-9]*\.[a-zA-Z]\{3\}\)$/\2/}' -e '/\([a-zA-Z]\)\{3\}$/!{s/\(.*\.\)\([a-zA-Z0-9]*\.[a-zA-Z]\{2,3\}\.[a-zA-Z]\{2\}\)$/\2/}' $arquivo
  20.  
  21. rm $arquivo
  22.  
  23. # --------------------------------------------------------------------------------- #
  24. # Quem não quiser usar apenas uma linha de sed, pode usar as duas linhas abaixo: ;) #
  25. # cut -d'/' -f3 teste.txt | sed -e '/\.[a-z]\{3\}$/!d' | rev | cut -d'.' -f-2 | rev #
  26. # cut -d'/' -f3 teste.txt | sed -e '/\.[a-z]\{3\}$/d' | rev | cut -d'.' -f-3 | rev  #
  27. # --------------------------------------------------------------------------------- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement