Firstly, you parse ls. This will fail with filenames containing whitespace. Then it pipe it to wc so you'd just get a count. Seems you've 948 files from Feb, probably..
cp 948 /smartapp/reports/archive_jan_feb_march/ won't work if you've no file named 948. Likely, you would want at least something like
ls -lrt | awk '$6 == "Feb" { print $9 }' | while read file
do
cp "$file" /smartapp/reports/archive_jan_feb_march/
done
which still suffers from errors of white space.
with bash you can do something like this.
touch -t 201201010000 start
touch -t 201204010000 end
for f in *; do
if [[ $f -nt start ]] && [[ $f -ot end ]]; then
cp "$f" /smartapp/reports/archive_jan_feb_march/
fi
done
Creating sentinels with touch is a nice approach, imo. A lot less messy and less error prone than trying to parse ls output (whose date format is locale dependent).
The -nt and -ot tests will also work with ksh.
For a more portable approach, find with -newer start and ! -newer end should work nicely. pax could then be used to handle all the copying without having to resort to many cp invocations.
find . -type f -name '.*txt' -newer start ! -newer end | pax -rw "$dest"
If recursing into subdirectories is undersirable, -maxdepth can be used. If not available, a slightly more cumbersome use of -prune can do the job.
Regards,
Alister
---------- Post updated at 10:37 AM ---------- Previous update was at 10:28 AM ----------
To my knowledge, all implementations of find which support -exec ... + require {} to be the word immediately preceding + .
-exec cp {} /destdir + will not work with most (if not all) implementations. If using GNU coreutils, cp can be made to work with the -t option.
@ Alister: Your absolutely right, + needs to follow {} immediately. So your cp -t proposal should apply. Sorry for not testing with cp, only echo... btw, how do you get those inline code tags?