Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- if [ $# -lt 1 ]
- then
- echo "Usage: $0 <file> <n1, n2, ...>"
- exit 1
- fi
- nr=0
- s=0
- k=0
- if [ -f $1 -a ! -L $1 ] # e ok, merge mai departe
- then
- while read n
- do
- rez=`echo $n | grep -Eo '[0-9]+'`
- if [ ! -z "$rez" ] # rezultatul nu e string gol (-z)
- then
- nr=$rez
- break
- fi
- done < $1
- echo "$nr"
- if [ $nr -eq 0 ]
- then
- echo "number not found"
- exit 1
- else
- for i in "${@:2}" # prin toate argumentele, incepand cu al 2-lea
- do
- if [ $(($i % $nr)) -eq 0 ]
- then
- k=$(($k + 1))
- fi
- s=$(($s + ${#i})) # suma cifrelor
- done
- fi
- else
- echo "$1 not a regular file"
- exit 1
- fi
- echo "$k numere divizible cu $nr"
- echo "suma cifrelor $s"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement