Share Pastebin
Guest
Public paste!

Peczenyj

By: a guest | Aug 7th, 2007 | Syntax: Bash | Size: 0.70 KB | Hits: 95 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. #!/bin/bash
  2. COR=`echo -ne '\e[31;1m'`
  3. END=`echo -ne '\e[m'`
  4. CORSED="1s/.*/${COR}&${END}/"
  5. GOOGLE='http://www.google.com/search'
  6.  
  7. [[ $2 ]] || { echo "usage: $0 item item2 [ ... item n]" ; exit 0 ; }
  8.  
  9. SEDCMD='/did not match any documents/{s/.*/0/g;p;q}
  10.        /Results/{s/.* about[ ]\+\([0-9,]\+\).*/\1\n/;p;q}'
  11.  
  12. AWKCMD='{ result[$1]=$2 ; x = length($1) ; if(x > max) max=x }
  13.        END{ for(i in result){ a = result[i] ; gsub(",","",a)
  14.                printf "%d\t%-"max"s%24s\n",a,i,result[i]}}'
  15.  
  16. for i in "$@" ; do echo -ne "${i}\t"
  17.         lynx -dump "${GOOGLE}?q=%22${i}%22" | tr -d $'\n' | sed -n "${SEDCMD}"
  18. done | awk -F '\t' "${AWKCMD}" | sort -nr | cut -d $'\t' -f 2- | sed "${CORSED}"