Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #if the number of arguments is not 3
- if [ $# -ne 3 ]
- then
- echo "USAGE: `basename $0` number1 number2 destination_folder"
- exit 1
- fi
- #if the directory exists remove it, then create it again
- if [ -d $3 ]
- then
- rm $3
- fi
- mkdir $3
- TO=$3
- number1=$1
- number2=$2
- #get all txt files from the home directory that have been modified between the last 10 and 14 days.
- txt_files=`find ./home -name "\.txt$" -type f -mtime +${number1} -mtime -${number2}`
- number_of_txt_files=`find ./home -name "\.txt$" -type f -mtime +${number1} -mtime -${number2} | wc -l`
- touch temp.txt
- i=0
- while [ i -lt $number_of_txt_files ]
- do
- #so we dump the files that are below or equal to 150B size and stick to more superior ones
- filesize=`ls -l ./home | grep ${text_files[${i}]} | awk 'print $4'`
- if [ filesize -gt 150 ]
- then
- echo "${txt_files[${i}]}" >> temp.txt
- fi
- i=`expr $i + 1`
- done
- for row in $(cat temp.txt)
- do
- #apparently this is how we count how many times a ceratin word appears in a file
- echo_count=`grep -o 'echo' $row | wc -l`
- #if there ain't a file with indexY.txt name where Y is the echo_count, make one and continue with another file
- if [ ! -f $TO/index${echo_count} ]
- then
- cp ./home/$row $TO/index${echo_count}.txt
- continue;
- fi
- #if there exists a file with that name, we add another digit character that kinda counts in a way how many files have the exact number of echos in em
- Zcount=1
- flag=0
- while [ flag -eq 0 ]
- do
- #if a file like this ain't existing, create it finally and get out, continue with another file
- if [ ! -f $TO/index${echo_count}${Zcount} ]
- then
- cp ./home/$row $TO/index${echo_count}${Zcount}.txt
- break;
- else
- #if a file like that exists try again by incrementing Z
- Zcount=`expr $Zcount + 1`
- fi
- done
- done
- #let us see what we've got...
- echo `ls -l | $TO | awk 'print $9'`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement