How to find files and then copy them to another

I must write any shell script.
I want find files which have .txt extension and then copy them to other, whithout this extension, for example:
I found linux.out.txt file, and now it must be copy to new, linux.out.
So: linux.out.txt -> linux.out
ubuntu.config.txt -> ubuntu.config
...
I tried many solutions..

find directory -type f -name *.txt | sed 's/.txt//'>file.txt

and here i have good new file names in file.txt file, but how should i run cp command ? :frowning:
Any ideas ? HELP

Hi,

Try This

 
#!/bin/sh
find directory -name "*.txt" | while read FILE
do
        newfilename=`echo $FILE | sed 's/.txt//g' | awk -F'/' '{print $NF}'`
        mv $FILE directory/$newfilename
done

ls -1 out.txt | while read rec
do
mv $rec /your/destination/dir/${rec%.
}
done

I've seen this magic recently

SRC=/source/directory
DST=/destination/directory
find $SRC -type f -iname "*.txt" -exec sh -c 'dest=$2; cp "$1" "$dest/$(basename ${1%.*})"' {} {} $DST \;

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.