May 15, 2011

Transfering text files in between a set of directories

#!/bin/ksh
# String manipulation
FILES=../Output/*
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
# string length
echo "length is ${#f}"
# substring of length 15 in variable f from the position 10. # g=${f:10:15}
# f contains file name in the format ../Output/ImmediateRecall10MinSet1_kuiper_OK
g=${f#*/} # delete the ../ from the begining
g=${g#*/} # Now delete the Ouput/ from the begining
g=${g%_*} # Now delete the _OK from the back
g=${g%_*} # Now delete the _kuiper from the back
echo "g is $g"
cp $f/*.txt $g/
done

No comments: