Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ##
- ## Socrate Rev. 0.79
- ## 2012 Dec 13, by R. J. Cano <aallggoorriitthhmmuuss@gmail.com>
- ## Released under GNU GPL 3.0 License - GO WITHOUT ANY WARRANTY WHATSOEVER.
- ##
- if [ $# == 1 ]; then
- export H=`wc -l $1 | cut -d' ' -f1`;
- if [ "$H" -gt "4" ]; then
- export workDir='patternprocessor.outcomes';
- export label_prefix='IdentifiedPattern_No';
- export label_suffix=0;
- mkdir $workDir > /dev/null 2> /dev/null;
- # These following three filenames are customary
- 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;
- 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;
- 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;
- touch palindromicpatterns.txt > /dev/null 2> /dev/null;
- echo " " >> palindromicpatterns.txt;
- echo " " >> palindromicpatterns.txt;
- echo " Identified patterns for $1:" >> palindromicpatterns.txt;
- echo -n "-------------------------" >> palindromicpatterns.txt;
- echo -n "-------------------------" >> palindromicpatterns.txt;
- echo "-------------------------" >> palindromicpatterns.txt;
- echo " " >> palindromicpatterns.txt;
- export H=`wc -l $1 | cut -d' ' -f1`;
- export ws=4;
- echo " ";
- echo "Processing $1; Please wait...";
- echo " ";
- while [ "$ws" -lt "$H" ]; do
- export ws=`echo "$ws+1" | bc -q`;
- export k=-1;
- while [ `echo "$k+$ws" | bc -q` -lt "$H" ]; do
- export k=`echo "$k+1" | bc -q`;
- head -n `echo "$k+$ws" | bc -q` $1 > $absurdfilename1;
- tail -n `echo "$ws" | bc -q` $absurdfilename1 > $absurdfilename2;
- tac $absurdfilename2 > $absurdfilename3;
- export key2=`md5sum $absurdfilename2 | cut -d' ' -f1`;
- export key3=`md5sum $absurdfilename3 | cut -d' ' -f1`;
- if [ $key2 == $key3 ]; then
- export label_suffix=`echo "$label_suffix+1" | bc -q`;
- echo "(ws, k, label, md5) ==> ($ws, $k, $label_suffix, $key2)";
- echo "(ws, k, label, md5) ==> ($ws, $k, $label_suffix, $key2)" >> palindromicpatterns.txt;
- cp $absurdfilename3 ./$workDir/$label_prefix$label_suffix.txt
- fi
- done
- done
- echo " ";
- echo " ";
- echo " It is done. These results were saved: Take a look to palindromicpatterns.txt, and the folder $workDir.";
- echo " ";
- rm -rf $absurdfilename1 > /dev/null 2> /dev/null;
- rm -rf $absurdfilename2 > /dev/null 2> /dev/null;
- rm -rf $absurdfilename3 > /dev/null 2> /dev/null;
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement