How to wite shell script to moves files?

Greetings to all,

i am new to shell scripting. i need to wite a script that moves files after renaming them to .txt . The exact scenario is this.
i have a directory /stsarie/btms/v5.0/report/wps where files will be imported from Host system periodically. Along with a file say named 130402-QASOUMI-5000000669 a 0 byte STMP file is also imported (STMP.130402-QASOUMI-5000000669) to esnsure complete file is copied.

i need to move the original file to another directory /stsarie/btms/v5.0/report/DS/App/inputFiles renaming the file to 130402-QASOUMI-5000000669.txt
Kindly help me.

Regards,

Try:

#!/bin/ksh
OD=/stsarie/btms/v5.0/report/DS/App/inputFiles
cd /stsarie/btms/v5.0/report/wps
for i in STMP.*
do      base="${i#STMP.}"
        mv "$base" "$OD/$base" && mv "$i" "moved.$i"
done

This was tested using the Korn shell, but will work with bash, ksh, or any other standards conforming shell.

Thanks a lot. its working perfectly...
:slight_smile: