Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using diff command, and ed command to reconstruct text 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I have a problem, I need to be able to extract the difference between two text files using the diff command and store them in a file on disk. I also need the ability to reconstruct the file using the original(first) file and the differences. I have looked at the Unix command diff and ed however I'm completely confused about how to use them! Any help for a Unix beginner? Cheers Iain
 
In it's simplest form, you can write the differences to a file using the following syntax:

diff file1 file2 > output_file

This will produce an output file containing:

1,5c1,5
< 1
< 2
< 3
< 4
< 5
---
> 6
> 7
> 8
> 9
> 10

for example.

I'm not sure what you are trying to do with ed, but if I get the chance I'll have a think about it.
 

Suppose multiple versions of a file :
File.0 Original file
File.1 Version 1
File.2 Version 2

Create ed scripts :
diff -e File.0 File.1 > File_0_1.ed ; Create ed script File.0 to File.1
diff -e File.1 File.2 > File_1_2.ed ; Create ed script File.1 to File.2


Create a script shell : reconstruct.sh
(shift; cat $*; echo '1,$p') | ed - $1

If you want to reconstruct the latest version of file from original file ad ed scripts :
resconstruct.sh File.0 File_0_1.ed File_1_2.ed > File.last ; = File.2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top