mnybud Posted September 8, 2008 Share Posted September 8, 2008 I have a very large text file, nearly 1 gig. I need to add some text before each line in the file. So for example I have 1 2 3 4 and I simply want a1 a2 a3 a4 I can do this in excel but since the file is so big it will have to be split into a million pieces in order to load and will take me forever. Is there a way to do this in php easily? Quote Link to comment Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 You would have to read in the entire file, append the the text to each line, then rewrite the entire file. Quote Link to comment Share on other sites More sharing options...
discomatt Posted September 8, 2008 Share Posted September 8, 2008 your best bet is to read in chunks http://php.net/fread then use str_replace( "\n", "\na" ); on the chunk then append the chunk to a new file. This will take a LONG time to execute, so use set_time_limit( 0 ), and possibly output flushing to give you an idea of the progress Quote Link to comment Share on other sites More sharing options...
mnybud Posted September 8, 2008 Author Share Posted September 8, 2008 thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.