Replacing all white spaces with commas in a 46MB text file

0

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

aneuryzm

Posted 2011-04-22T07:34:21.710

Reputation: 1 765

What exactly are you asking? Have you tried it yourself? If yes, do you think it's taking too long? – Siim K – 2011-04-22T07:40:05.483

Should be near instantaneous, if not instant... – studiohack – 2011-04-22T07:40:12.077

This is 46MB... I dunno about textmate, but a lot of text editors choke on files that large, textmate may not be working 100% properly. – jcrawfordor – 2011-04-22T07:50:05.650

@nimble @studiohack It is actually running since 20 minutes. That's why I'm asking. I just need some quick tip how this is usually done. Maybe some other text editor? – aneuryzm – 2011-04-22T08:02:23.000

Answers

3

Using sed from Terminal this would take a few seconds:

sed -i "s/ /,/g" bigfile

(In my test, 565786 spaces in a 46 MB binary file were replaced in 2.1 seconds.)

Vim works too (:%s/ /,/g) but was a little slower.

Edit: s/[[:space:]]/,/g to include tabs (which, I assume, you meant by "whitespace")

user1686

Posted 2011-04-22T07:34:21.710

Reputation: 283 655