Forums Register Login

Command to compare two files starting from first line till Mid

+Pie Number of slices to send: Send
I need help on Unix command or script.
I need to two compare two files as follows: -
file1 contains 500 recs
file2 contain 1500 recs

I need to get the different between file 1 & 2 and to be writen 1000 recs in file3. but the tricky is the in both files don't want to compare the whole line. the line length of 640 and I want to compare only 630 length.

Please help me.

Waiting for your kind reply.
+Pie Number of slices to send: Send
Cady Cady, welcome to JavaRanch. Please check your private messages. You can see them by clicking My Private Messages.
+Pie Number of slices to send: Send
Does file2 contain all the records that are in file1? If so, then a simple script can look for the partial line in file2 and if it is not there then grab it from file2:



If there are too many records to do this, then you might want to ensure that both files are sorted then run either a more advanced script (awk or perl) or write a Java program to do the work for you.

Regards, Andrew
+Pie Number of slices to send: Send
 

run either a more advanced script (awk or perl) or write a Java program to do the work for you.

Or of course a C/C++ app if you have the resources to do so. Java has such large overheads on startup and memory consumption that it usually isn't suited for these sorts of small, fast jobs (it is however excellent for portable long running processes where RAM isn't a constraint). Whenever I have to parse a lot of files in some custom way, it's always faster (than grep, awk and certainly perl) to write a native program to do it. I'll use a shell script if the files are small and I need a quick or rapidly portable solution, but it's C/C++ otherwise... Compiling on Linux is dead easy too---just install gcc/g++ via your package manager and run it on the source files. It's almost as easy on Windows with MinGW, but programming with VC++/VS is quite a different experience.
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2209 times.
Similar Threads
JTree - Compare Nodes problem
need help!!! please
diff in two files in UNIX,, help me
Using Jar Files
Ant copy files by reading property file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:37:59.