The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
merging of 2 files AWK, SHELL or something else klut Shell Programming and Scripting 24 03-20-2009 09:45 AM
merging text files code19 Shell Programming and Scripting 8 02-13-2008 08:13 AM
Merging two files venommaker UNIX for Dummies Questions & Answers 4 01-10-2008 08:15 AM
merging INPUT and files fiol73 UNIX for Dummies Questions & Answers 1 01-01-2007 05:14 PM
Merging fileds from 2 files Mudshark Shell Programming and Scripting 8 04-19-2005 01:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-28-2004
rameshonline rameshonline is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 17
merging two files

Hi everyone,

I have two files which will be exactly same at first. After sometime there will be inserts in one file. My problem is how to reflect these changes in second file also.

I found out that any compare and merge utility would do the job like, GNU " sdiff " command. But the problem with sdiff is, it is an interactive tool. we have to tell the command what to do each time it finds a difference in the files. (Either merge the change or discard it by specifying 'l' , 'r' ..options)

do any one of you know how to automate this process.... or any other utility is available for doing this?

(sort with -m option is not what i want ..because i dont want to lose the order in the files)

Thanks in advance
  #2 (permalink)  
Old 06-28-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
cp firstfile secondfile
will ensure that any changes made to the first file are reflected in the second file.
  #3 (permalink)  
Old 06-28-2004
rameshonline rameshonline is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 17
hi perdarabo,

i am sorry to miss out an important point above.. My second file also can have inserts at the end but not in the middle...so if we do cp we will loose second file changes.

(to put it differently, i am looking at two files which are same at first but after sometime both will change)
  #4 (permalink)  
Old 06-28-2004
dkaplowitz dkaplowitz is offline
Registered User
  
 

Join Date: Jun 2004
Location: ~Philadelphia
Posts: 63
Code:
cp firstfile secondfile
will "clobber" the 2nd file. (clobber = completely replace/overwrite everything in "secondfile").

If you want to append data from firstfile, try
Code:
firstfile >> secondfile
, which appends the contents of firstfile to secondfile. Make sure there are two ">>" b/c only one ">" does the same thing as the above cp command. This is explained in good shell programming books under "input/output redirection".
  #5 (permalink)  
Old 06-29-2004
PaulC PaulC is offline
Registered User
  
 

Join Date: Mar 2004
Location: Esher, Surrey, England.
Posts: 31
Quote:
Code:
firstfile >> secondfile
Surely all that is going to do is attach the entire content of firstfile onto the end of second file rather than just what has been updated.

Doesn't he want to take two data files that start with the same content, update both files with different sets of data and merge those 2 files into 1 file that contains all the data without replicating anything ?? (If you follow what I mean..)

I'm not sure if there are any UNIX commands that could do it, but I would look at using Perl or similar...

Last edited by PaulC; 06-29-2004 at 03:23 AM..
  #6 (permalink)  
Old 06-29-2004
dkaplowitz dkaplowitz is offline
Registered User
  
 

Join Date: Jun 2004
Location: ~Philadelphia
Posts: 63
Quote:
Originally posted by PaulC
Surely all that is going to do is attach the entire content of firstfile onto the end of second file rather than just what has been updated.

Doesn't he want to take two data files that start with the same content, update both files with different sets of data and merge those 2 files into 1 file that contains all the data without replicating anything ?? (If you follow what I mean..)

I'm not sure if there are any UNIX commands that could do it, but I would look at using Perl or similar...
You're right. I didn't read his post clearly enough. The rsync utility can help: http://rsync.samba.org (is usually avail in most distros as well) It works locally as well as remotely and can use ssh for added security.
  #7 (permalink)  
Old 06-29-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Perhaps take a look at comm.

comm -23 prints only lines in the first file but not in the second
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0