Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Command to compare two files starting from first line till Mid

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cady Cady, welcome to JavaRanch. Please check your private messages. You can see them by clicking My Private Messages.
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic