Advertisement
razvanth21

SO - Bash Script Test #2

Dec 1st, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.36 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. if [ $# -ne 2 ]
  4. then
  5.     echo "Usage: $0 <file> <prefix>"
  6.     exit
  7. fi
  8.  
  9. k=0
  10. s=0
  11.  
  12. while read str
  13. do
  14.     if [ $str = "End" ]
  15.     then
  16.         break
  17.     else
  18.         if [[ "$str" =~ ^$2.* ]]
  19.         then
  20.             echo $str
  21.  
  22.             k=$(($k+1))
  23.             s=$(($s+${#str}))
  24.         fi
  25.     fi
  26. done <&0
  27.  
  28. if [ -f $1 ]
  29. then
  30.     echo "$k siruri, suma=$s" > $1
  31. else
  32.     echo "not a regular file"
  33. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement