Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.78 KB | None | 0 0
  1. !/bin/bash
  2. # this script creates an outfile with "val" number of lines of   digits with the columns aligned ...
  3. # but formating only works to 999 so far , but its eay to extend,
  4. #  WARNING: you will still need to edit the outfile to add or remove ...
  5. #        since this script cant perfectly write  to 64,128,256,512... and such
  6. # mike , undergrad, friday,4th,2011.
  7. # hope it makes your work easier!!
  8.  
  9.  
  10. if [ $# -eq 0 ]
  11. then
  12.    echo " "  
  13. fi
  14.  
  15. myarray=(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
  16. count=0
  17. n=0
  18. val=25                  #change this to the number of lines you want ie if 1..50 , val~3 since there are
  19.                         # roughly five  lines of digits
  20.  
  21. echo -n " even or odd ? "
  22. read -e TYPE
  23.  if [ "$TYPE" =  "even" ]
  24.   then let  type=2
  25.   else let  type=1
  26.  fi
  27.  
  28. tens=99
  29. hundreds=999            #you would need to add other variables like t...r than 999
  30.  
  31. i=0
  32. if [ "$type" -eq 2 ]; then    ###########      for the even list of digits
  33.  
  34.  echo >> outfile$type
  35.  for i in ${myarray[@]}
  36.            do
  37.         if (( ("$i" % 2) ==  "0" )); then
  38.            sed '$s/$/ '$i'/' -i outfile$type
  39.           # echo $i
  40.            if   [ "${myarray[$i]}" -gt  "10" ] ; then                                                                                                                    
  41.                sed '$s/$/  /' -i outfile$type                                                                                                                          
  42.            else   sed '$s/$/   /' -i outfile$type   #his adjusts the space betw....the forward slashes      
  43.            fi                                                                                                                                                          
  44.         fi                                                                                                                                                            
  45.            done                                                                                                                                                        
  46.   echo >> outfile$type                                                                                                                                                
  47.   while [ $n -le $val ]                                                                                                                                                
  48.    do                                                                                                                                                                  
  49.         for i in ${myarray[@]}                                                                                                                                        
  50.            do                                                                                                                                                          
  51.             myarray[$count]=`expr $i + 20`                                                                                                                            
  52.             ((count++))
  53.            done
  54.          count=0
  55.  
  56.  
  57.        for i in ${myarray[@]}
  58.            do
  59.          if (( ("$i" % 2) == "0" )) ; then          # check if its odd or even
  60.            sed '$s/$/ '$i'/' -i outfile$type
  61.               if [ "${myarray[0]}" -le "$tens" ] ; then
  62.                   sed '$s/$/  /' -i outfile$type         # adjusts space betwe...the ones digits
  63.    
  64.                 elif [ "${myarray[0]}" -le "$hundreds" ]; then
  65.                  sed '$s/$/ /' -i outfile$type           #this adjusts........igned with the ones & tens
  66.  
  67.                          #ld add such elifs from here to... extend the column alignment beyond 999
  68.                else                                  
  69.                  sed '$s/$/ /' -i outfile$type            #adjusts space after hundreds
  70.               fi
  71.          fi
  72.            done
  73.            echo >> outfile$type
  74.  
  75.          let n++
  76.   done
  77.  
  78.  
  79.  
  80. else                                          ## for odd numbers
  81.  
  82. echo >> outfile$type
  83.  for i in ${myarray[@]}
  84.            do
  85.         if (( ("$i" % 2) !=  "0" )); then
  86.            sed '$s/$/ '$i'/' -i outfile$type
  87.            if  [ "${myarray[$i]}" -gt  "10" ]; then
  88.                sed '$s/$/  /' -i outfile$type
  89.            else   sed '$s/$/   /' -i outfile$type   #s adjusts the space between the ones dig...ashes
  90.            fi
  91.         fi
  92.            done
  93.  
  94.   echo >> outfile$type
  95.  
  96.   while [ $n -le $val ]
  97.    do
  98.  
  99.         for i in ${myarray[@]}
  100.            do
  101.             myarray[$count]=`expr $i + 20`
  102.             ((count++))
  103.            done
  104.          count=0
  105.  
  106.  
  107.        for i in ${myarray[@]}
  108.            do
  109.          if (( ("$i" % 2) != "0" )) ; then          #    check if its odd or even
  110.            sed '$s/$/ '$i'/' -i outfile$type
  111.               if [ "${myarray[0]}" -le "$tens" ] ; then
  112.                 sed '$s/$/  /' -i outfile$type       # adjusts space between the tens...be               elif [ "${myarray[0]}" -le "$hundreds" ]; then
  113.                  sed '$s/$/ /' -i outfile$type           #...ds digits to be aligned with the ones & ...
  114.  
  115.                          # you would add such elifs from here to extend the........
  116.                else
  117.                  sed '$s/$/ /' -i outfile$type            # adjusts space after hundreds
  118.               fi
  119.          fi
  120.            done
  121.            echo >> outfile$type
  122.  
  123.          let n++
  124.   done
  125. fi
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. this is the error message thought the script does what its intended to do:
  136.  
  137.  
  138.  ./Onetofive: line 40: [: : integer expression expected
  139.  
  140. funny thing is that it only gives the error message when i choose the "even"
  141. choice , but still does what its intended, the "odd" does not give any error message
  142.  
  143. i'v highlighted line 40
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement