Speed up perl operations on large files

Feb 26, '02 10:55:45PM

Contributed by: Anonymous

Yesterday I was faced with a 21 megabyte text file that needed several find/replace operations. Tex-Edit would open the file, but not change it. BBEdit would chug through the changes, but it was taking forever. I dropped into a Terminal window and used:

perl -pi -e 's/find/replace/g' filename
However, this too was slow -- much slower than I expected.

Because I was checking the file in Tex-Edit after each find/replace, the process was taking some time, until on a whim I used Tex-Edit to change the line endings from "Mac" to "Unix" style.

From that point on, the 'perl s/' command ran blazingly fast.

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2002022622554549