Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.53 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.     fi
  40. done
  41. fi
  42.  
  43. else
  44.  echo "$1 is not a regular file"
  45.     exit 1
  46. fi
  47.  
  48. echo "$s"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement