Check the changes made to file in vi


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Check the changes made to file in vi
# 1  
Old 09-22-2010
Check the changes made to file in vi

Hi,

I use vi editor in Unix.

Is there any way if we can know that what change was made to the file opened in vi before quitting?
As i opened a huge file made some changes yesterday and didnt save it.
Today when i was quitting the vi , i came to know that some changes are made(as i got warning with q option).I need to know what changes were made , so i can save it or discard it.

Is there any way of doing this?

Thanks,
Kailash
# 2  
Old 09-22-2010
If your file is called "edit-this", try
Code:
more .edit-this.swp

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 09-22-2010
Code:
:w /tmp/current
:!diff -c /tmp/current % | less



---------- Post updated at 23:53 ---------- Previous update was at 23:52 ----------

Quote:
Originally Posted by Scrutinizer
If your file is called "edit-this", try
Code:
more .edit-this.swp

This is vim specific.
This User Gave Thanks to jlliagre For This Post:
# 4  
Old 09-22-2010
Thanks fo reply.
But no success , i dont have that swap file.

---------- Post updated at 04:57 PM ---------- Previous update was at 04:54 PM ----------

Well , yes there's option to save the file with diff name and compare Smilie

Thanks.

---------- Post updated at 04:59 PM ---------- Previous update was at 04:57 PM ----------

Scrutinizer,

I dont have vim , if its vim specific ;thats why it didn't work.
I will try to check with vim.
Thanks
# 5  
Old 09-23-2010
kailash19, what scrutinizers and jiliagres suggestions have in common is this:

As vi opens a file it creates a backup copy somewhere. Depending on the specific flavour of vi or vim you use it might be in different locations: the vi under AIX creates this file in /var/tmp, vim uses .<filename>.swp in the same directory as the file, etc.. Real vi's delete this backup copy upon leaving the editor, but some vi-clones (like vim) retain these files until explicitly configured to do otherwise.

By using the "diff" utility you can compare the text you have right now in your editing buffer (the file in the open editing session) and the contents of this backup copy of the original file and find out the differences. You can even write these differences to a file and open this in another editor window as vi is multi-windowed (see the ":e", ":n" and ":rew" commands in the man pages).

I hope this helps.

bakunin
# 6  
Old 09-23-2010
To clarify, I wasn't suggesting to use any backup file that vi itself possibly creates by itself but to save the current buffer in a temporary file and compare it to the original one. This can be done simply with the two commands I already posted:
Code:
:w /tmp/current
:!diff -c /tmp/current % | less

(replace less by more if less is missing).
The backup files created by the traditional vi in /var/tmp aren't usable for that task as not being a plain copy of the current file but a structured binary designed to allow file recovery should the editor crashed (vi -r). This applies also to vim .swp files which aren't either editable text files.
# 7  
Old 09-23-2010
Thanks all for your replies.

I used diff for the rescue Smilie .

Discussion was knowledgeable.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I add a log file path to a vi file to monitor all the changes made to the file?

I'm curious to know how do I add an empty log file (test1.log) to an existing text file to monitor all the changes made to a.txt. Is this expression export PATH=$PATH:/home/test1.log right to be added to the text file a.txt? (5 Replies)
Discussion started by: TestKing
5 Replies

2. Shell Programming and Scripting

Vi : Is it possible to send ctrl + d signal from a file made with vi and executing it.

Hi Experts, Is it possible to send ctrl + d signal from a inside a file made with vi, using Ctrl V , Esc and 004 , escape sequence. Since : 004 should exit the script if executed. Is this something possible. I am trying with vi , I put this code ^ , and trying to execute it but... (4 Replies)
Discussion started by: rveri
4 Replies

3. AIX

How to check changes made in last few weeks?

Hi, I want to know what changes were made to my AIX system in last few weeks/months. Is there any command that I can use for this? I am facing a problem wherein my program which are built few weeks back runs fine but if I build the same program now, it doesn't run as expected. ... (4 Replies)
Discussion started by: shriashishpatil
4 Replies

4. Solaris

Before I delete any file in Unix, How can I check no open file handle is pointing to that file?

I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command. I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file. Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies

5. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

6. Shell Programming and Scripting

strtotime() error - no changes made

Not sure what happened, this page/code always worked before, no changes were made to the code, only the box was powered down, moved and powered back up, the code seems to still be doing its job but spewing out these errors right on the page. Again no changes were made. Warning: strtotime()... (1 Reply)
Discussion started by: ippy98
1 Replies

7. Programming

Problem in reflecting changes made on a JSP File

I make some changes in a JSP file but the changes do not reflect on tomcat server. In my server.xml 'reloadable' paramtere is set to true. I even treid restarting the server. The changes still not reflect. The changes do reflect in a day or two. am not sure why this is happening. Shall... (3 Replies)
Discussion started by: Shikha Agrawal
3 Replies

8. UNIX for Dummies Questions & Answers

monitor changes made by root

Is there any way in Solaris 9 to monitor changes made to user accounts by root? (0 Replies)
Discussion started by: scriptarg
0 Replies

9. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies

10. Shell Programming and Scripting

How do i check if changes were made to a file using vi

okay, heres the thing I'm creating a script that I can use to create users. no, this is not a homework assignment or whatever it may seem. i'm just trying to master shell programming. how can I pass arguments in a file to useradd????? when i say arguments, I mean, all the arguments and... (1 Reply)
Discussion started by: TRUEST
1 Replies
Login or Register to Ask a Question