Quote:
Originally Posted by Shruthi GM
... to compare two files without using diff command or its better to use diff command.
|
Hi Shruti and welcome to LQ,
I also wanted to ask, why not simply use diff?
Then I thought, let me just answer your question as a general interrogation. Firstly, yes, we can write a script to compare two files. It will require many lines of codes as you will need to take file names as arguments, test if they exist and are valid files, read line by line and at the same time worry about file format, then finally compare and output the results intelligently. To sum up, it will take a good amount of time to do that and I am not sure it will be better than diff.
So, let's use diff instead. You can do the job very easily with a one line command. People have put considerable effort in developing a nice program as diff so that you don't have to go through all the hassle of writing the program yourself. So, you can be pretty sure it will work quite nicely.
And as the people before you did, if someday you have an original idea for a command or a useful script, you can develop it, so that the people after you can benefit. This is part of the philosophy of open source and "Linuxing" in general.