Replacing the existing files only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing the existing files only
# 1  
Old 04-11-2011
Replacing the existing files only

Hey,

Can someone pls give me an idea on how to write a shell script for the below requirement.

I am generating lot of .txt files in a unix directory through a etl tool, now I need to write a shell script which will move these files to another directory(\abc\xyz\source), but in the \abc\xyz\source same file may exsit , if the file with the same name is exsiting then I need to remove the exsiting file file and replace those files with the newly created file from the ETL tool.

Example:- In my source dir I have the below files.
1.txt
2.txt
3.txt

and in the target directory I have

4.txt
5.txt
3.txt
1.txt

Now I want the shell script to move all the files from source dir and replace the files in the target directory, this replace should happen for only those files which are exsiting in the source dir.so my output should be as below.

1.txt
2.txt -- this should be replaced, i.e existing file should be removed and new file should be placed here.
3.txt -- this should be replaced, i.e existing file should be removed and new file should be placed here.
4.txt
5.txt

Thx,
Shruthi
# 2  
Old 04-11-2011
just use mv with -f option (do not prompt before overwriting)

Code:
$ mv -f /abc/xyz/source/* /abc/xyz/target/

# 3  
Old 04-12-2011
Hey Thanks a lot.., I was thinking all the other ways except the mv -f.


Once again Thanks a lot.

Thx,
Shruthi
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Creating the script for updating or replacing the existing http.conf file

Hi I need some help with a task, i am an absolute newbie to any form of shell scripting and request guidance. I have been building a proxy server using the apache mod proxy currently my solution is working , but i need to automate the process , suppose if any changes need to be made on... (0 Replies)
Discussion started by: satej
0 Replies

2. Solaris

Command to remove existing files in the tar files in Solaris 10

Hi, I am using solaris 10 OS.Please help me out with the commands needed in below two scenarios. 1)How to delete the existing files in the tar file. suppose i have a main tarfile named application.tar and it contains a file called ingres.tar. what is the command to remove ingres.tar... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

3. Shell Programming and Scripting

Appending new column to existing files

Hi, i want to add another column to existing files containing strings and need to have the final output as a csv file. i have quite a number of files, each with varying number of rows and i need to append the string "test" for all the valid rows for each file. my sample raw files looks like this... (8 Replies)
Discussion started by: ida1215
8 Replies

4. UNIX for Dummies Questions & Answers

Count number of files in directory excluding existing files

Hi, Please let me know how to find out number of files in a directory excluding existing files..The existing file format will be unknown..each time.. Thanks (3 Replies)
Discussion started by: ammu
3 Replies

5. Shell Programming and Scripting

overwriting existing files with scp.

Ok. I am using one cluster to remotely write into another cluster. I can scp to copy files from cluste1 to cluster2, however, I need to copy a file that already exists in cluster 2 and replace it with the new file. I was thinking I could either remove the file in cluster 2 (which I don't know how... (2 Replies)
Discussion started by: libertyforall
2 Replies

6. Shell Programming and Scripting

How to copy one folder to another with existing files

For example, /tmp/folder1 includes /tmp/folder1/a /tmp/folder1/b /tmp/folder2 includes /tmp/c Is there a command without removing files in /tmp/folder2 first to copy the /tmp/folder1 to /tmp/folder2? and the result should be /tmp/folder2 will include only /tmp/folder2/a... (2 Replies)
Discussion started by: lalelle
2 Replies

7. UNIX for Dummies Questions & Answers

usermod -G and Group id login replacing existing groups

Hi all usermod -G Group_id login it is replacing the existiong Secoundry groups and is adding the only group speced in usermod command how can we retain the existing secoundry groups and add a user to a new group (6 Replies)
Discussion started by: pbsrinivas
6 Replies

8. Solaris

ls does not display existing files

Hi, I have a pecular problem that I am experiencing. I have a few directories that seems to be missing, however, I can vi the files within them and I can also execute them (script files). For missing, I mean when I issue the "ls" command I don't see anything. Any help will be greatly... (1 Reply)
Discussion started by: copperUser
1 Replies
Login or Register to Ask a Question