In thinking about this, you may not need to sort the files in order to determine if they have the same content. The steps to use diff or cmp are that the files are sorted -- read once -- then compared character by character -- read again.
I wrote a short perl code that simply adds the bytes in the files together. It will not matter if the characters are re-arranged or not, the sum will always be the same. An additional advantage is that this is not restricted to text files. Here is the code:
The driver code is long, so I will paste only the results of calling the perl code with 6 files, each one of a pair being a rearrangement of the other. The sum then will be the same for all files that have an identical set of characters, regardless of position in the file. Samples of the file content is shown:
Of course, if you consider 2 lines such as:
to be different, then this approach will not be satisfactory.
Best wishes ... cheers, drl
Last edited by drl; 08-09-2009 at 09:04 PM..
Reason: Edit 1: add disclaimer
If I have 3 kinds of files in directory DATA1:
FileA.20060315.dat, FileB.20060315.dat, FileC.20060315.dat
FileC.20060316.dat
FileA.20060317.dat, FileB.20060317.dat
FileA.20060318.dat, FileB.20060318.dat, FileC.20060318.dat
If 3 files have the same date then run
$cat FileA.20060315.dat... (3 Replies)
Dear All.
Im trying to know how exactly the command "compare" works, does it compare line by line or field by field, and the most important thing is that why the files have to be sorted before we compare them?
Thanks in advance (7 Replies)
I have four files, I need to compare these files together.
As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes.
Please suggest if you know some commands whcih can... (6 Replies)
Hello all -
I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Team,
I have two files and I am trying to find the lines unique to file1. So i have executed the below command at shell prompt and got the correct results
comm -23 <(sort test) <(sort test1)
When i run the same command in Bash shell script, i got the correct results.
But when i run... (5 Replies)
Hello All,
Iam using below method to sort and compare files. First iam doing sorting and changing the same file and then doing comparing and taking the final result to another file.
sort -o temp.txt file1
mv temp.txt file1
sort -o temp.txt file2
mv temp.txt file2
sort -o temp.txt... (6 Replies)
To make it easier, i gave following example. It is not homework or classwork. Instead, i have a huge csv file dump from tsql with 15 columns and around 300 rows. I was able to extract content that needs to be really converted. Here is the extract:
ES FP,B1ES FP,70000,I,SL22,SL22 (70000)
ES... (0 Replies)
To make it easier, i gave following example. It is not homework or classwork. Instead, i have a huge csv file dump from tsql with 15 columns and around 300 rows. I was able to extract content that needs to be really converted. Here is the extract:
ES FP,B1ES FP,70000,I,SL22,SL22 (70000)
ES... (8 Replies)
Hello,
I am new to Unix and would like to seek a help, please.
I have 2 files (file_1 and file_2), I need to perform the following actions.
1 ) Sort the both file by the column 26-36 (which is Invoice number)
what is sort command with the column sort?
2) Compare the file_1.sorted and... (3 Replies)