#-- FILE: #-- randw.sh #-- DESCRIPTION: #-- This script copies a number of files, chosen #-- at random, into a sub-directory. #-- #-- AUTHOR: #-- mj bishop #-- DATES: aug 02 if [ "$1" = "" ] then echo ' Usage: ./randw.txt numberOfFiles [subDirectory] This script selects a specified number of files from the current directory randomly and copies them into a sub-directory numberOfFiles is the number of files which will be copied into the sub-directory subDirectory is the name of the sub-directory where the files will be copied. This defaults to a subdirectory named 'Lesson1' ' exit 1 else iFiles=$1 fi if [ "$2" = "" ] then sSubDirectory=Lesson1 else sSubDirectory=$1 fi ls | grep 'wav$' > fileList.txt iFileCount=$(cat fileList.txt | wc -l | sed 's/^ *//g') # echo "fc="$iFileCount echo ' Copying files into subdirectory ' for m in $(awk "BEGIN{for (p=0;p<$iFiles;p++) {print p}}") do file=$(cat fileList.txt | awk "BEGIN{srand();n=int(rand()*$iFileCount);} NR==n") echo "copying file=$file" cp $file $sSubDirectory done #-- infinite loop (until user presses q)