• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replace pattern in huge file

 
Abhi Venu
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


I need to read a large text file (90 MB) file da replace a pattern let be 'xyz' with 'PQR' .I need to create a new file with this change.

How can this be done in most efficent way in minimum time.

I did it in a way but it took 25 mnts Also i tried with BufferedInputStream and stringbuffer.But igot out of memory error.I dont want to increas the heap size and try it.

Please help me in the approach i should choose

Regards
abhi
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please KeepItDown, not only in your post text but also in your subjects.
 
H Paul
Ranch Hand
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I beginner. And the only concept that stick to my head is 'Divide and Conquer'.

Technically, Is it feasible and/or advisable that we divide the big file into N small files and let each be taken by a thread.
When all threads are done. Merge the files...

This is like dividing the job into N persons rather than letting 1 person do it alone.






 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have to use Java? It might be more efficient at a UNIX command line.
 
H Paul
Ranch Hand
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question now is why not?
 
Jon Avadis
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybee you can post your code. I did similar things with 30MB files in a matter of seconds, processing them line by line,
and i cant see why it would take this long for a 90MB file.
 
Abhi Venu
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Jon Can you post your code please. Also i would like to know how it is done in UNIX and if any windows eqiuvalent for the same.


Regards
Abhi
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you post your code first? If Jon posts his code, you won't learn anything. As for how UNIX does it, there's a command line tool called sed that can help with this.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could also write a one-line perl script to do it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic