Advertisement
algorithmuscanorj

Untitled

Dec 14th, 2012
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.35 KB | None | 0 0
  1. #!/bin/bash
  2. ##
  3. ## Socrate Rev. 0.79
  4. ## 2012 Dec 13, by R. J. Cano <aallggoorriitthhmmuuss@gmail.com>
  5. ## Released under GNU GPL 3.0 License - GO WITHOUT ANY WARRANTY WHATSOEVER.
  6. ##
  7. if [ $# == 1 ]; then
  8. export H=`wc -l $1 | cut -d' ' -f1`;
  9. if [ "$H" -gt "4" ]; then
  10. export workDir='patternprocessor.outcomes';
  11. export label_prefix='IdentifiedPattern_No';
  12. export label_suffix=0;
  13. mkdir $workDir > /dev/null 2> /dev/null;
  14. # These following three filenames are customary
  15. export absurdfilename1=`echo $RANDOM | replace  0 a 1 b 2 c 3 d 4 e 5 x 6 y 7 z 8 V 9 W`$RANDOM$RANDOM;
  16. export absurdfilename2=`echo $RANDOM | replace  0 a 1 b 2 c 3 d 4 e 5 x 6 y 7 z 8 V 9 W`$RANDOM$RANDOM;
  17. export absurdfilename3=`echo $RANDOM | replace  0 a 1 b 2 c 3 d 4 e 5 x 6 y 7 z 8 V 9 W`$RANDOM$RANDOM;
  18. touch palindromicpatterns.txt > /dev/null 2> /dev/null;
  19. echo " " >> palindromicpatterns.txt;
  20. echo " " >> palindromicpatterns.txt;
  21. echo "    Identified patterns for $1:" >> palindromicpatterns.txt;
  22. echo -n "-------------------------" >> palindromicpatterns.txt;
  23. echo -n "-------------------------" >> palindromicpatterns.txt;
  24. echo "-------------------------" >> palindromicpatterns.txt;
  25. echo " " >> palindromicpatterns.txt;
  26. export H=`wc -l $1 | cut -d' ' -f1`;
  27. export ws=4;
  28. echo " ";
  29. echo "Processing $1; Please wait...";
  30. echo " ";
  31. while [ "$ws" -lt "$H" ]; do
  32. export ws=`echo "$ws+1" | bc -q`;
  33. export k=-1;
  34. while [ `echo "$k+$ws" | bc -q` -lt "$H" ]; do
  35. export k=`echo "$k+1" | bc -q`;
  36. head -n `echo "$k+$ws" | bc -q` $1 > $absurdfilename1;
  37. tail -n `echo "$ws" | bc -q` $absurdfilename1 > $absurdfilename2;
  38. tac $absurdfilename2 > $absurdfilename3;
  39. export key2=`md5sum $absurdfilename2 | cut -d' ' -f1`;
  40. export key3=`md5sum $absurdfilename3 | cut -d' ' -f1`;
  41. if [ $key2 == $key3 ]; then
  42.   export label_suffix=`echo "$label_suffix+1" | bc -q`;
  43.   echo "(ws, k, label, md5) ==> ($ws, $k, $label_suffix, $key2)";
  44.   echo "(ws, k, label, md5) ==> ($ws, $k, $label_suffix, $key2)" >> palindromicpatterns.txt;
  45.   cp $absurdfilename3 ./$workDir/$label_prefix$label_suffix.txt
  46. fi
  47. done
  48. done
  49. echo " ";
  50. echo " ";
  51. echo " It is done. These results were saved: Take a look to palindromicpatterns.txt, and the folder $workDir.";
  52. echo " ";
  53. rm -rf $absurdfilename1 > /dev/null 2> /dev/null;
  54. rm -rf $absurdfilename2 > /dev/null 2> /dev/null;
  55. rm -rf $absurdfilename3 > /dev/null 2> /dev/null;
  56. fi
  57. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement