So as to not confuse people, I also removed a couple of comments that basically just talked about the formatting issues with the original hint. I've left the remainder of the comments, however, and actually chose to refer to sweth's explanation directly in the hint, as it's much clearer than mine ever was! I also adjusted the command per his comments on "w" vs. "S," and re-titled the hint to make it a bit less confusing.
Finally, for those who commented that this hint doesn't belong here, I'd just like to point out that we have 1,226 other Unix tips in the system, and I have no intention of not publishing such tidbits. If you have no interest in seeing Unix tips, registered users can easily disable the entire category in their preferences. But OS X is built on Unix, and to claim that a Unix tip isn't relevant to OS X just isn't accurate.
-rob.
Yesterday, I was doing some global editing on a relatively large text file, and accidentally made one change too many, saved changes, and quit the editor before I noticed the problem. The result? My file was now littered with sentences that ran together at the period:
...my bearers would hurl me.As they bore me along...
...glanced at the thermometer."Gad!" he cried...
...might make reparation.I made up my mind that...
For the curious, those lines are from Edgar Rice Burroughs' book At the Earth's Core, the text of which I'm using in a comment spam blocker I'm writing for my blog site. I was editing the text to remove some of the spurious punctuation that was causing my code to misinterpret the position of word breaks, and I got overly aggressive removing some spaces. Read on to see how I resolved it with some help from a friend, and the Unix underpinnings of OS X.
I knew what I needed to do to fix the problem -- "find all instances of some character, followed by the period, followed by some other character, and add a space before that last character." But I couldn't figure out how to make that seemingly simple change. I tried using BBEdit and a couple other text editors to do my "search and replace back into," but had no luck. So I called on a friend who has tons of Unix, perl, and regular expression experience. He came up with a one-line perl solution for me:
perl -pe 's/(\S)([.])(\S)/$1$2 $3/g' source.txt > final.txt
Though this looks complex, when he explained it to me, it made at least a bit more sense. When I originally published this hint, I intended (and had drafted) my own explanation as to how that worked. But due to mistakes on my part, that explanation never made it online. Thankfully, user sweth provided an excellent writeup on how the command in the comments -- I'd ask that you just read that explanation in lieu of my feeble attempt.

