Files rename and copy

hello,

I am write a Script and i would listing all Files from Path1 out with DSR*.txt and give a new name an copy to the Path2.

I have problems with that to rename. Someone can help me?

Sorry, for my english. My english is not gut.
I hope you understand my.

That is my Script.

# **********************************************************
# Variablen setzen
# **********************************************************
heute=`date +%Y%m%d`
text_datum=`date +%d"."%m"."%Y`
text_zeit=`date +%T`
system_datum=`date +%d"."%m"."%Y`
JAHR=`date +%Y`
MONAT=`date +%m`
ftp_path=/export/home/ftp/lukb
swx_path=/export/home/smb/swx
# Sind Files f�r das Kopieren vorhanden
if [ ! -f ${APSYS_DAT}/RSD*.txt ] ; then
  echo "Es sind Keine Files da um zu Kopieren"
  exit 0
fi

# **********************************************************
# Erstellen Ordner f�r die Sicherung
# **********************************************************
# Erstelle ein Jahres Verzeichnis
# **********************************************************
if [ ! -d ${swx_path}/${JAHR} ] ; then
  echo "Das Verzeichnis ${swx_path}/${JAHR} wird erstellt"
  mkdir ${swx_path}/${JAHR}
fi
# **********************************************************
# Erstellen das Monats Verzeichnis
# **********************************************************
if [ ! -d ${swx_path}/${JAHR}/${MONAT} ] ; then
  echo "Das Verzeichnis ${swx_path}/${JAHR}/${MONAT} wird erstellt"
  mkdir ${swx_path}/${JAHR}/${MONAT}
fi

# **********************************************************
# SWX
# **********************************************************
 
  echo Files nach /export/home/smb/swx kopiert
  cp ${APSYS_DAT}/RSD*.txt ${swx_path}
  cp ${APSYS_DAT}/RSD*.txt ${swx_path}/${JAHR}/${MONAT}
  echo "Das File wird im Ver. DAT gel�scht"
  rm ${APSYS_DAT}/RSD*.txt

If I understand, you want to not only move the files, but rename them too. Right?

Here's one way. This adds -heute- in the middle of the name, right after "RSD":

for FILE in ${APSYS_DAT}/RSD*.txt; do
    BASE="$(basename "$FILE")"
    mv "$FILE" "$swx_path/${BASE/RSD/RSD-${heute}-}"
done

Do any of the files have spaces in the names? That would make it a little trickier.

Hi,
Rigth? Of the files dont have spaces.
I have corrected my script and i hope that will be the right solution.

#!/bin/sh


# Variable Laden
# ************************************************** **
# Wenn Job nicht laufen sollte EXIT ohne Fehler verlassen
# ----------------------------------------------------------------

# ************************************************** **
# Variablen setzen
# ************************************************** **

heute=`date +%Y%m%d`
text_datum=`date +%d"."%m"."%Y`
text_zeit=`date +%T`

system_datum=`date +%d"."%m"."%Y`
JAHR=`date +%Y`
MONAT=`date +%m`

ftp_path=/export/home/ftp/lukb
swx_path=/export/home/smb/swx

# Sind Files f�r das Kopieren vorhanden
if [ ! -f ${APSYS_DAT}/RSD*.txt ] ; then
echo "Es sind Keine Files da um zu Kopieren"
exit 0
fi


# ************************************************** **
# Erstellen Ordner f�r die Sicherung
# ************************************************** **
# Erstelle ein Jahres Verzeichnis
# ************************************************** **
if [ ! -d ${swx_path}/${JAHR} ] ; then
echo "Das Verzeichnis ${swx_path}/${JAHR} wird erstellt"
mkdir ${swx_path}/${JAHR}
fi
# ************************************************** **
# Erstellen das Monats Verzeichnis
# ************************************************** **
if [ ! -d ${swx_path}/${JAHR}/${MONAT} ] ; then
echo "Das Verzeichnis ${swx_path}/${JAHR}/${MONAT} wird erstellt"
mkdir ${swx_path}/${JAHR}/${MONAT}
fi


# ************************************************** **
# SWX
# ************************************************** **

echo Files nach /export/home/smb/swx kopiert

for i in RSD*.txt; do

mv ${APSYS_DAT}/$i ${swx_path}/${heute}_${i}
mv ${APSYS_DAT}/$i ${swx_path}/${JAHR}/${MONAT}/${heute}_${i}

done

# echo "Das File wird im Ver. DAT gel�scht"
# rm ${APSYS_DAT}/RSD*.txt

# if [ -z "$2" ] ; then break ; fi