#!/bin/bash if [ ! -f ./list ];then echo "Please make a file named 'list' containing the info of each content in a line." exit 1 fi rm -f /tmp/list if [ $? = 1 ];then echo "I could not remove /tmp/list. I will abort." exit 1 fi if [ -e ./randomizedlist ];then ls ./randomizedlist echo "" echo "There is ./randomizedlist. Can I delete it? If I can, type y." read a if [ "$a" = "y" ];then rm -r ./randomizedlist if [ $? = 1 ];then echo "I could not delete ./randomizedlist. I will abort." exit 1 fi else echo "I cannot generate ./randomizedlist. I will abort." exit 1 fi fi cp ./list /tmp/list if [ $? = 1 ];then echo "I could not copy ./list to /tmp/list. I will abort." exit 1 fi touch ./randomizedlist i=$(wc -l ./list|cut -d " " -f 1) echo "The number of the lines of ./list is $i." while [ $i -gt 0 ];do n=$(echo $[$RANDOM*i/32767+1]) echo "$n th line is selected." sed -n -e ${n}p /tmp/list >> ./randomizedlist sed -i -e ${n}d /tmp/list i=$[$i-1] done rm -r /tmp/list exit 0