Help with using grep command with copy command

Hi, im taking an entry Unix class, and as part of my lab assignment I have to copy all files in the /home/david/lab3 directory that have the file extension .save to your lab3/temp directory. I'm having trouble getting the grep to do anything worth while

I've been trying to do:

cp /home/david/lab3 /home/user113/lab3 | grep '.save'

and havnt gotten it to work yet. Am I using the right context? I really am at a loss here. Also, when I try to run "grep '.save' in the /home/david/lab3 directory i dont get any output, and i have to ctrl+d to get back to a prompt. Any help would be appreciated, I have to finish this lab by 6:30pm EST.

edit: I'm using the Bourne shell.

cd /home/david/lab3
for i in ls *.save
do
cp $i /home/user113/lab3
done 

this should work:

cp `ls /home/david/lab3/*.save` /home/david/lab3/temp

I get an error:


[user113@vbitblnx1 lab3]$ ls
my.names  mynames.save  names  names.020807  names1  names.sav  names.save  pass
[user113@vbitblnx1 lab3]$ cp 'ls /home/david/lab3/*.save' /home/user113/temp
cp: cannot stat `ls /home/david/lab3/*.save': No such file or directory

---------- Post updated at 02:29 PM ---------- Previous update was at 02:23 PM ----------

Okay i think i got it
pwd
/home/david/lab3
cp *.save /home/user113/lab3 works for me

grep matches regular expressions. The regexp for a string (filename), followed by a dot, followed by another string (extension) would be something like: grep '.*\.save$'

However you don't need to use grep at all; It can be done with a single command, using wildcards:

cp /your/path/*.save /destination

EDIT: Oh, well... my reply was too late. :frowning: Anyway, glad you figured it out by yourself. :smiley:

yep, thats exactly what i did. Thanks a bunch guys.

cd /home/david/lab3
for i in ls *.save
do
cp $i /home/user113/lab3
done

^^^ above will also work if you modify the 1st line by adding 'tics':
for i in `ls *.save`

Cheers
Momin