Shell Script that identifies changes between 2 files and then combines them


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell Script that identifies changes between 2 files and then combines them
# 1  
Old 04-15-2008
Shell Script that identifies changes between 2 files and then combines them

Hi,

I've been trying to figure out a script that would enable me to find the changes made from an original file say x then to a duplicate called y then revert those changes.

Simple, but I'm already cracking my head over this one, Can someone help me out?

say file x:-

abc1
def2
ghi3
jkl

then file y:-

abc
def
ghi3


What do I do?
# 2  
Old 04-15-2008
diff will create an ed script that can change one file to another. Read the man page for diff. The script will take file1 and make it be the same as file2, if you want - and if I got what you mean.
# 3  
Old 04-15-2008
Hi Jim,

Thanks I looked into doing diff onto those files and can see it but am now trying to figure out the scripting part that can do it.

example:-

it's executed being able to take in 2 arguments

$ ./compare.ksh file1 file2

first it makes a backup of file1 called file1.ori
then it compares what is in file2
then adapts file2 into file1
# 4  
Old 04-15-2008
Is there a reason you cannot simply use the cp command to copy file1 to file2?
# 5  
Old 04-16-2008
Hi.

I think Jim's solution is the simplest.

If you are interested in the series of changes to a file (a history, versions, etc.), two basic tools that you could consider are rcs and bzr. See man pages for details ... cheers, drl
# 6  
Old 04-16-2008
For version control, also look at subversion and CVS ... and git and darcs and monotone and mercurial and what have you (-:

Seriously, if you want version control, you probably want something more than just rcs, which is very old. bzr is one of a large group of "next-generation" tools but it's by no means the only one, although it's fairly popular.
# 7  
Old 04-16-2008
Quote:
I think Jim's solution is the simplest.
Agree!

If you want to see the differences in two files, I personally find sdiff "or if your OS supports it, xdiff" these give more human readable output.


Code:
sdiff file1 file2 
# use -s flag if you only want to see differences.
# if you expect large amount of changes, redirect output to a file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find and removing the old files and zipping the files using shell script

Hi, I am trying to removing the old files which were older than 10 days and same g zipping the files using the shell script. script was return as follows. find /jboss7_homes/JBOSS7/SKYLIV??/SKYLIV??_CRM/jboss-eap-7.0/standalone/log -mtime +10 -type f | xargs rm -f find /cer_skyliv??/log... (6 Replies)
Discussion started by: venkat918
6 Replies

2. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

3. Shell Programming and Scripting

Combines all lines in two files

The below awk combines the target.txt with the out_parse.txt and the output is GJ-53.txt (all attached). If there are multiple lines in out_parse how can they both be writing to GJ-53.txt? For example, in out_parse.txt there are two lines: 13 20763612 20763612 C T... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

5. Shell Programming and Scripting

Using Shell Script in place of Perl script to Unzip the zip files.

Hi Expert, We have some shell scripts which Internally uses Perl Script to Unzip the source zip files which comes to inbound directory. So now our requirement is to avoid the dependency on Perl Script and us Shell Script to unzip the files. I have the Perl script with me attached can some one... (3 Replies)
Discussion started by: naveen.dasu
3 Replies

6. Shell Programming and Scripting

Read files in shell script code and run a C program on those files

HI, I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this: 1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

7. Shell Programming and Scripting

need a shell script to extract the files from source file and check whether those files existonserve

Hi, I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is # echo $0 -sh My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies

8. Shell Programming and Scripting

Files copying - [ Listed files alone. ] - Shell script

Hi All, I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files. To Do From Directory : /myproject/MainDir To Directory : /myproject/data List of files need to copy is in the file: /myproject/filesList.txt ... (4 Replies)
Discussion started by: linuxadmin
4 Replies

9. Shell Programming and Scripting

To Create shell script files from a shell script

Dear Unix and Linux users, Good evening to all. I'm new to this community and thank you for having an wonderful forum. Dear members i had to create almost some 300 shell script files for a particular task. I tried something like this.... #!usr/bin/sh fname=epdb_jobs for x in `cat $fname`... (3 Replies)
Discussion started by: NehaB
3 Replies
Login or Register to Ask a Question