Files rename and copy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Files rename and copy
# 1  
Old 01-12-2010
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.


Code:
# **********************************************************
# 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


Last edited by Scott; 01-12-2010 at 06:02 PM.. Reason: Please use code tags
# 2  
Old 01-12-2010
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":
Code:
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.
# 3  
Old 01-13-2010
Hi,
Rigth? Of the files dont have spaces.
I have corrected my script and i hope that will be the right solution.

Code:
#!/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


Last edited by Scott; 01-13-2010 at 06:26 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oop to copy and rename files through SQL Statement in shell Script

#!/bin/sh sqlplus -s "/ as sysdba" << EOF SET HEADING OFF SET FEEDBACK OFF Select pt.user_concurrent_program_name , OUTFILE_NAME FROm apps.fnd_concurrent_programs_tl pt, apps.fnd_concurrent_requests f where pt.concurrent_program_id = f.concurrent_program_id and pt.application_id =... (1 Reply)
Discussion started by: usman_oracle
1 Replies

2. Shell Programming and Scripting

Linux Script to copy and rename files through SQL statement

Hi, I require help to complete below requirement through Linux Script. I have a SQL query which shows two columns as output. One is Report Name and other is report path. Query return multiple rows. below is the output. Report Name Cotton Stock Report (Net Weight)- Customized Output... (3 Replies)
Discussion started by: usman_oracle
3 Replies

3. Shell Programming and Scripting

Is better way copy list of multiple files, rename and gzip

Is better way to write the script loop through one by one "Old_File_1: & New_File_1:" to copy 100 files to /staging/test folder then re-name & gzip all those files? I wrote this code below and don't like that much. Thanks I have a control_file under /tmp/test folder like below 100 files and... (10 Replies)
Discussion started by: dotran
10 Replies

4. Shell Programming and Scripting

Copy down remote files and rename them to include the server name with full path

I need to pull down a good bit of files for another support team for an upgrade project. I have a server.list with all of the server names. I need to do two parts: FIRST: I have this example, but it does not list the server name in front of each line. #! /bin/bash for server in $(<... (10 Replies)
Discussion started by: asnatlas
10 Replies

5. Shell Programming and Scripting

Help with script to copy/rename files, then delete by date

Hi All, I am new to scripting and am looking for some assistance setting up a script. Basically I need the script to scan a folder for the newest files and make a copy of those files, adding a month to the date stamp. I also need this script to delete the previously copied files to save space.... (4 Replies)
Discussion started by: Lucid13
4 Replies

6. Shell Programming and Scripting

copy and rename file..

hi all, I have one config folder and updates folder.updates folder contains file tmp_2.0_20201208_45.xml and config folder contains file tmp.xml.When the tmp_2.0_20201208_45.xml file is copied in the config folder the name of this file is changed in config folder again as tmp.xml(old... (8 Replies)
Discussion started by: shubhig15
8 Replies

7. Shell Programming and Scripting

Copy files from folder and rename them

hello, I need to build a shell script that receives the folder to copy by parameter and copy all files except thumb.db to another folder and rename them like, file.jpg renamed to file_bb1.jpg. can someone help me Thanks (4 Replies)
Discussion started by: zeker
4 Replies

8. UNIX for Dummies Questions & Answers

script to rename files with current date and copy it.

I have few webservers logs like access.log. which would be growing everyday. what i do everyday is, take the backup of access.log as access.log_(currentdate) and nullify the access.log. So thought of writing a script... but stuck up in middle. My requirement: to take the backup and nullify... (6 Replies)
Discussion started by: logic0
6 Replies

9. UNIX for Dummies Questions & Answers

copy and rename list of files

Hi all, I am a newbie in writng unix..I am using ksh shell..Does anyone know how to copy a list o files from directory A to directory B with differnt names? i.e in Dir A, I have RPT101.555.TXT RPT102.666.TXT and I want to copy those files to dir B with new naming convention.. in Dir B,... (7 Replies)
Discussion started by: kinmak
7 Replies
Login or Register to Ask a Question