Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.62 KB | None | 0 0
  1. #!/bin/bash
  2. ################# this script creates an outfile with "val" number of lines of   digits with the columns aligned . val can be set to what you want
  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 the final last digits to the desired final number
  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 this to extend column alignment to greater 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   ######this adjusts the space between the ones digits , space is added or removed bbetween 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         ######### this adjusts space between the tens digits to be aligned with the ones digits
  63.    
  64.                 elif [ "${myarray[0]}" -le "$hundreds" ]; then
  65.                  sed '$s/$/ /' -i outfile$type           ######### this adjusts the space between the hundreds digits to be aligned with the ones & tens
  66.  
  67.                          ######## you would 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   ######this adjusts the space between the ones digits , space is added or removed bbetween the forward slashes
  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         ######### this adjusts space between the tens digits to be aligned with the ones digits
  113.  
  114.                 elif [ "${myarray[0]}" -le "$hundreds" ]; then
  115.                  sed '$s/$/ /' -i outfile$type           ######### this adjusts the space between the hundreds digits to be aligned with the ones & tens
  116.  
  117.                          ######## you would add such elifs from here to extend the column alignment beyond 999
  118.                else
  119.                  sed '$s/$/ /' -i outfile$type            ######## adjusts space after hundreds
  120.               fi
  121.          fi
  122.            done
  123.            echo >> outfile$type
  124.  
  125.          let n++
  126.   done
  127. fi
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. this is the error message thought the script does what its intended to do:
  138.  
  139.  
  140.  ./Onetofive: line 40: [: : integer expression expected
  141.  
  142. funny thing is that it only gives the error message when i choose the "even"
  143. choice , but still does what its intended, the "odd" does not give any error message
  144.  
  145. i'v highlighted line 40
  146.  
  147.  
  148. here is what it gives with "set -x"
  149.  
  150. + ./Onetofive
  151.  
  152. even or odd ? even
  153. ./Onetofive: line 40: [: : integer expression expected
  154. ++ echo -ne '\033]0;mike@localhost:~/work/worksub/scripts'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement