You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

  1. SAMESTR="ThisIsTheSameString" #Same String for uniq
  2. readonly SAMESTR
  3. ##
  4. # Get random integar between 1 and 100
  5. ##
  6. function getRandomName(){
  7. rnd=`expr $RANDOM % 64 + 1`
  8. return $rnd
  9. }
  10. ##
  11. # Get random string, first parametar is length
  12. ##
  13. function getRandomString(){
  14. openssl rand -base64 $1
  15. }
  16. function generate(){
  17. size=500
  18. i=0
  19. while(( $i < $size ))
  20. do
  21. getRandomName
  22. length=$?
  23. #echo "START"
  24. if [[ $length -ge 1 && $length -le 25 ]]
  25. then
  26. echo $SAMESTR
  27. else
  28. echo `getRandomString $length`
  29. fi
  30. let "i++"
  31. done
  32. }
  33. function sortByASCII(){
  34. generate | sort | uniq -u
  35. }
  36. function sortByNumeric(){
  37. generate | sort --numeric-sort | uniq -u
  38. }
  39. echo "Overwrite lines:" > resultASCII #this line should not appear in output file
  40. sortByASCII > resultASCII
  41. echo "Append lines:" >> resultASCII #this line should appear in output file
  42. sortByASCII >> resultASCII
  43. echo "Overwrite lines:" > resultNumeric #this line should not appear in output file
  44. sortByNumeric > resultNumeric
  45. echo "Append lines:" >> resultNumeric #this line should appear in output file
  46. sortByNumeric >> resultNumeric
  47. echo "Number of same string in file:"
  48. generate > randomLines
  49. grep --only-matching $SAMESTR < randomLines | wc --lines