riccardinofuffolo

Sistemi Operativi - 09/09/2009 - Es. 5

Aug 15th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.58 KB | None | 0 0
  1. #!/bin/bash
  2. # Uso: istogramma.sh dati.txt
  3.  
  4. sort -k 1,1 $1 > output.tmp
  5. max=$(tail -1 output.tmp|awk '{print $1}')
  6.  
  7. i=1
  8. puntatore=1
  9. rm -f result.txt
  10. while (( $i<=$max ))
  11. do
  12.     linea=$(head -$puntatore output.tmp | tail -1)
  13.     numero=$(echo $linea|awk '{print $1}')
  14.     if (( $numero == $i ))
  15.     then
  16.         stringa=""
  17.         asterischi=$(echo $linea|awk '{print $2}')
  18.         for (( j=0 ; j < asterischi ; j++ ))
  19.         do
  20.             stringa="$stringa*"        
  21.         done
  22.         echo "$i $stringa" >> result.txt
  23.         puntatore=$(( $puntatore+1 ))
  24.     else
  25.         echo "$i" >> result.txt
  26.     fi
  27.     i=$(( $i+1 ))  
  28. done
  29.  
  30. rm -f output.tmp
Advertisement
Add Comment
Please, Sign In to add comment