bashshellunixed

Invert the 'ed' command for reverting back to previous file version


I am doing a version control project in Unix using bash script. How can I move from the current version to a previous version without having to build a new file from scratch to the required version. Is there a way to invert the ed scripts to move backwards?

I have a file, and a folder with all the version files (in ed script). The version files containing the ed scripts were created using the command,

diff -e $path.$1_dir/.temporaryFile $1 > $path.$1_dir/.v$fileCount

$path --> variable holding the path, $fileCount --> variable holding the version number for the files, .temporaryFile --> temp file built to the latest available version.

I am able to build the temporary file from scratch to the latest version using,

(cat $path.$1_dir/.v$i) | ed - $path.$1_dir/.temporaryFile

$i --> iter in a for loop


Solution

  • Instead of using ed directly, you can use patch, which also drives ed, and use the -R option to apply the changes in the reverse direction.