I am looking for a method to effectively search and replace text in large file(1 GB). 1. i tried to read line by line but it is taking over 2 hrs for the process to complete. 1. i tried to readllalines or readtoend but these are erroring out with memory exception Can anybody suggest other methods so that process can complete in few minutes.
Asked
Active
Viewed 182 times
0
-
2Read in chunks? See [How can I read/stream a file without loading the entire file into memory?](https://stackoverflow.com/questions/6865890/how-can-i-read-stream-a-file-without-loading-the-entire-file-into-memory) – Alex K. Oct 04 '18 at 12:56
-
1Hey, could you show us your code? – Oct 04 '18 at 12:56
-
Possible duplicate of [Reading large text files with streams in C#](https://stackoverflow.com/questions/2161895/reading-large-text-files-with-streams-in-c-sharp) – Schwarzie2478 Oct 04 '18 at 13:01
-
If you need random access to the file: https://learn.microsoft.com/en-us/dotnet/api/system.io.memorymappedfiles.memorymappedfile?redirectedfrom=MSDN&view=netframework-4.7.2 – Schwarzie2478 Oct 04 '18 at 13:03
-
2Post code. There's nothing inherent in your problem that would make it take that long. Please tell me you're using a second file to store output and then copying it back over the original. Doing it inline in the same file is the classic worst case performance scenario for arrays if your replacement text and replaced text are not the same size. – hoodaticus Oct 04 '18 at 13:12
-
The I/O won't improve much over ReadLine() or EnumerateLines(). There is something else at play here. – bommelding Oct 04 '18 at 13:35