SHARE
TWEET

SO - Bash Script Test #2

razvanth21 Dec 1st, 2018 (edited) 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top