File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Command to compare two files starting from first line till Mid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Command to compare two files starting from first line till Mid" Watch "Command to compare two files starting from first line till Mid" New topic
Author

Command to compare two files starting from first line till Mid

Abdul Mohd
Greenhorn

Joined: Oct 19, 2008
Posts: 1
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

Cady Cady, welcome to JavaRanch. Please check your private messages. You can see them by clicking My Private Messages.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11503
    
  95

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
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.


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Command to compare two files starting from first line till Mid