Advertisement
Guest User

Untitled

a guest
Dec 18th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.48 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. texte=$(cat $1 | sed "s/[^a-Z|0-9| |-|]/ /g; y/àâéèêëîïôöùûü/aaeeeeiioouuu/; y/ÇÀÂÉÈÊËÎÏÔÖÙÛÜ/çAAEEEEIIOOUUU/; s/$/ /g" | tr -d '\n' | tr -s ' ' | tr '[:upper:]' '[:lower:]')
  4.  
  5. nombremot=$(wc -w <<< "$texte")
  6. #nombreligne=$(wc -l <<< "$texte")
  7.  
  8. if [ "$(tail -c 2 <<< "$texte")" = ' ' ]
  9.     then
  10.         texte="$(rev <<< "$texte" | cut -c2- | rev)"
  11. fi
  12.  
  13. if [ "$(head -c 1 <<< "$texte")" = ' ' ]
  14.     then
  15.         texte=$(cut -c2- <<< "$texte")
  16.         #echo "$texte"
  17. fi
  18.  
  19. tableau_texte=( $texte )
  20.  
  21. texte=$(tr ' ' '\n' <<< $texte)
  22.  
  23. #set -x
  24.  
  25. OK=0
  26. occurence_max=0
  27. until [ $OK = $nombremot ]
  28.     do
  29.         occurence=0
  30.  
  31.  
  32.         mot=$(sed -n $((OK + 1))p <<< "$texte")
  33.         lignepresencemot=$(grep -nx "${tableau_texte[$OK]}" <<< "$texte" | cut -d : -f 1 | tr '\n' ', ')
  34.  
  35.  
  36. #set -x
  37. #echo $occurence_max
  38.         for test1 in $(grep -nx "${tableau_texte[$OK]}" <<< "$texte" | cut -d : -f 1 | sort -r | tr '\n' ' ')
  39.             do
  40.                 occurence=$((++occurence))
  41.             done
  42.  
  43.             typeset tableau_${occurence}+="$mot ${lignepresencemot:0:-1}##"
  44.  
  45.     if [ $occurence -gt $occurence_max ]
  46.         then occurence_max=$occurence
  47.     fi
  48.  
  49. #set +x
  50. #set -x
  51.  
  52.         OK=$((++OK))
  53. done
  54.  
  55.  
  56. OK=1
  57. until [ $OK -gt $occurence_max ]
  58.     do
  59.         arraytruc="tableau_$OK[*]"
  60.         echo "${!arraytruc}" | tr '##' '\n' | awk ' !x[$0]++'
  61.         # literal variable http://stackoverflow.com/questions/7142965/bash-array-parameter-expansion-within-parameter-name-bad-substitution
  62.         OK=$((++OK))
  63. #echo $OK
  64. done
  65. #set +x
  66. unset tableau_texte
  67.  
  68. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement