Sponsored Content
Top Forums Shell Programming and Scripting how to synchronize different dirs Post 302099163 by reldb on Saturday 9th of December 2006 03:56:30 PM
Old 12-09-2006
how to synchronize different dirs

I have 4 directory

Dir1
file1 file2 file3 file4
Dir2
file3 file5 file6 file8
Dir3
file1 file2 file6 file9 file10
Dir4
file3 file6 file12 file15

and all the 4 dirs are having couple of files.
Few of the files are common to other directory/ies and few of them are brand new.

I need a finaloutput as
dir1 having all the files from all other 3 directory but not having its original files same for other dirs. And i need to change the file name in dir1. Actually all the files are having a ext as .text so i need to remove the .text from all the files.

eg
dir1 file5 file6 file8 file9 file10 file12 file15
dir2 file1 file2 file4 file9 file10 file12 file15


I am doing like this

newdir1 - copying all the files from dir2 dir3 and dir4
then delete the files from newdir1 which are there in dir1
so this way newdir1 is my final result.
Doing the same for other directory

>mkdir newdir1
> cp dir2/* ./newdir1
> cp dir3/* ./newdir1
> cp dir4/* ./newdir1

ls dir1 | while read file; do
rm ./newdir1/${file}
done
cd newdir1

ls | while read file; do
mv ${file} `echo ${file} | sed 's/\.txt//'`
done



Is there any other best and fast way to do? Actually i need some way which can be much more efficient than this instead of using 2 while loops as i have more than 5000 files in each folder and most of them are common across each folder only 20 are new files.

can i do this through file manipulation means instead of working on actual file if i make a file with all the filename and then doing some commands on names instead of actual file and then finally copying the actual file

Last edited by reldb; 12-09-2006 at 05:13 PM..
 

9 More Discussions You Might Find Interesting

1. Programming

synchronize as in java

Hi, I am trying to implement the synchronize feature of java using C. I am using a semaphore for the same. I have a wrapper called "synch" to which I pass the function pointer(any_fn). This pointer points to the function (my_fn) which needs to be synchronized. However to create the semaphore I... (8 Replies)
Discussion started by: linuxpenguin
8 Replies

2. Shell Programming and Scripting

How to synchronize all the linux machine?

Hi, I have three Linux machine have three different times. Can I synchronize them using one process? I have root access. Thanks! (1 Reply)
Discussion started by: whatisthis
1 Replies

3. Programming

need a way to synchronize processes

I am writing a program in C for my networking class, so I am relatively new to this. To begin, I have 7 processes that need do send messages to every other one, and every one of them needs to receive the messages sent by others. I am using fork() to create 6 more processes. The message... (1 Reply)
Discussion started by: inabramova
1 Replies

4. UNIX for Advanced & Expert Users

synchronize processes

hi. i am writing a c program under bash shell. i would like to use semaphore functions like sem_wait(), sem_post() and i included <semaphore.h> and it compailes fine but when i try to run it gives me an error "undefined reference to sem_wait() , sem_post() , sem_init()" what have i missed... (2 Replies)
Discussion started by: emil2006
2 Replies

5. Programming

synchronize two processes

i am trying to synchronize between father process and son process created by fork() command, to print simultaneously. my program is written in c under bash shell. the compile goes ok but when i try to run nothing happens and the program doesnot end. my code is: #include <stdio.h>... (1 Reply)
Discussion started by: emil2006
1 Replies

6. Shell Programming and Scripting

Synchronize Files-Help

Hi, I have two servers1&2, one is not in the network. Cant communicate from it to other servers. The second one can communicate to above mentioned server. I am trying a script which synchronizes files between server 1 an 2? server1: cant communicate to any other servers server2: can... (4 Replies)
Discussion started by: Tuxidow
4 Replies

7. Shell Programming and Scripting

How to synchronize using FTP

Hi everyone! I need to write a script that will synchronize two servers using FTP. So basically the script will get only the files that exist on the remote server that do not exist on the local server. Is there an option to do this when using mget? If not, is there a way to copy over only the... (2 Replies)
Discussion started by: Fatbob
2 Replies

8. UNIX for Dummies Questions & Answers

**HELP** how to do a listing of dirs and all sub dirs only

I am trying to get a listing of ALL directories only under /export (as an example). I can get all the dirs directly under /export but I need any sub dirs under those dirs. I've looked (here and google) but can not find anything that works (4 Replies)
Discussion started by: bbraml
4 Replies

9. UNIX for Advanced & Expert Users

How to synchronize two different files?

Hello, I have the latest stable release of a UNIX-like O.S. in the ISO format, and want to synchronize it with the latest Release Candidate (RC) of it, in order to reducing bandwidth usage. The ISO images for that O.S. is provided via different protocols including rsync, FTP and HTTP Is this... (4 Replies)
Discussion started by: temp-usr
4 Replies
diff3(1)						      General Commands Manual							  diff3(1)

NAME
diff3 - 3-way differential file comparison SYNOPSIS
file1 file2 file3 DESCRIPTION
compares three versions of a file, and prints disagreeing ranges of text flagged with these codes: all three files differ file1 is different file2 is different file3 is different The type of change required to convert a given range of a given file to some other is indicated in one of these ways: Text is to be appended after line number n1 in file f, where f = or Text is to be changed in the range line n1 through line n2. If n1 = n2, the range can be abbreviated to n1. The original contents of the range follows immediately after a indication. When the contents of two files are identical, the contents of the lower-numbered file is suppressed. Produces a script for the editor that can be used to incorporate into file1 all changes between file2 and file3 (see ed(1)); i.e., the changes that normally would be flagged and Produces a script to incorporate only changes flagged Produces a script to incorporate only changes flagged Produces a script that will incorporate all changes between file2 and file3, but treat overlapping changes (that is, changes that would be flagged with in normal listing) differently. The overlapping lines in both files will be inserted by the edit script bracketed by and lines. Produces a script that will incorporate only changes flagged , but treat these changes in the manner of option. The following command applies the resulting script to file1. EXTERNAL INFLUENCES
International Code Set Support Single- and multi-byte character code sets are supported. WARNINGS
Text lines that consist of a single period defeat Files longer than 64K bytes do not work. FILES
SEE ALSO
diff(1). diff3(1)
All times are GMT -4. The time now is 08:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy