Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.56 KB | None | 0 0
  1. #! /bin/sh
  2.  
  3. if [ $# -lt 2 ]
  4. then
  5.     echo "Usage: $0 <file> n1 n2 ..."
  6.     exit 1
  7. fi
  8.  
  9.  
  10. s=0
  11. nr=0
  12.  
  13.  
  14. if [ -f $1 ]
  15. then
  16. while read line
  17. do
  18.      rez=`echo $line | grep -Eo '[0-9]+'`
  19.     if ! [ -z "$rez" ]
  20.     then
  21.         nr=$rez
  22.         break
  23.     fi
  24. done < $1
  25.  
  26. echo "$nr"
  27.  
  28.  
  29. if [ $nr -eq 0 ]
  30. then
  31.     echo "Number not found"
  32. else
  33.  
  34. for i in "${@:2}"
  35. do
  36.     if [ $(($i % $nr)) -eq 0 ]
  37.     then
  38.     s=$(($s + ${#i}))
  39.     echo "Nr $i are ${#i} cifre"
  40.     fi
  41. done
  42. fi
  43.  
  44. else
  45.  echo "$1 is not a regular file"
  46.     exit 1
  47. fi
  48.  
  49. echo "$s"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement