Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

How long should replacing all white spaces with commas take in my 46MB text file using a simple text editor such as textmate on my Mac?

share|improve this question
    
Will probably also depend on the number of spaces in your document. Is it a "normal text document" or some kind of "data document". I tend to believe it's the second one due to the uncommon need. –  LudoMC Apr 22 '11 at 7:50
    
@LudoMC yeah exatly, plenty of white spaces (each word is followed by one and the file is 46MB, I'm on intel duo dual core and it is still running after 20 minutes. –  Patrick Apr 22 '11 at 8:03

2 Answers 2

up vote 10 down vote accepted

TextMate can sometimes be very slow with big files like this.

I recommend using a command line utility like sed.

sed 's/ /,/g' orig.txt > modified.txt

will do what you need extremely quickly. Obviously replace the filenames with your actual filenames.

share|improve this answer
    
thanks for the command line, but it doesn't work. Are you sure blank is replacing white spaces ? What I get is a file which is exactly the same of the original one –  Patrick Apr 22 '11 at 8:20
    
I need to replace word1 word2 with word1,word2 for example –  Patrick Apr 22 '11 at 8:20
    
I edited the answer. Put a space in-between the first two / slashes. Let me know how that goes. –  RobZolkos Apr 22 '11 at 8:31
    
perfect thanks –  Patrick Apr 22 '11 at 8:33

This should be even faster than the sed solution:

tr ' ' , < orig.txt > modified.txt
share|improve this answer
    
But of course, unless you need to do this a lot, the speedup hardly matters. –  Harald Hanche-Olsen Apr 22 '11 at 10:18
    
Nice. Didn't think of tr. Just did an experiment. sed took 0.002 seconds and tr took 0.333 seconds on the same source file. Both solutions would significantly beat using TextMate though ;) –  RobZolkos Apr 22 '11 at 10:23
3  
Textmate would probably send you the results by postal mail… ;) –  Martín Marconcini Apr 22 '11 at 11:52
    
@RobZolkos: You may wish to try a bigger source file in order to get a meaningful measurement. On a 236 MB file, tr takes 12 seconds while sed needs 30 seconds to get the job done on my machine. If I change from my usual UTF-8 locale to a C locale, the times drop to 10 and 15 seconds respectively. –  Harald Hanche-Olsen Apr 22 '11 at 12:30
    
Yeah, @Harald - good point. I was testing on a relatively small file ;) –  RobZolkos Apr 22 '11 at 12:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.