Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command to compare two files starting from first line till Mid

 
Abdul Mohd
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15644
47
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cady Cady, welcome to JavaRanch. Please check your private messages. You can see them by clicking My Private Messages.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic