BASH Scripting: Inserting text into a fixed location of a file

Ever need to insert some test into the middle of a file? Turns out there's a pretty simple way to do it! Assume you want to put the contents of "addition.txt" into "myfile.txt" at line 10:

head -n 10 myfile.txt > output.txt
cat addition.txt >> output.txt
tail -n +10 myfile.txt >> output.txt
mv output.txt myfile.txt

Of course, 10 can be changed to a variable, and file names can be changed to variables.


Book Review: Here Comes Everybody

Recently appearing on the Colbert Report, Clay Shirky talked about his new book Here Comes Everybody. I thought it was a good interview and sounded like a good book, and then promptly forgot about it. Then I read an article I found on reddit: Gin, Television, and Social Surplus. It was easily the most insightful thing I'd read all day. Then I noticed the URL and decided to buy the book when I flew back to Cleveland for CWRU Commencement. This was one of those rare books that's hard to put down; I really hadn't been this engrossed since I read the Da Vinci Code in two days. Don't let the easy reading fool you; that just proves how well written it was.

One of the topics Shirky explores involves the activity of edits on a Wikipedia page. If you look at the revisions a page has gone through, most people who have touched the page make very small changes, and there's a very active minority who are responsible for the bulk of the work. This distribution follows the power law (I really enjoyed linking that to the Wikipedia page, btw). The power law, in brief, is a sharp curve that shows a skewed distribution (think back to Algebra II when you graphed 1/x on your TI-83). This is odd in that an "average" Wikipedia contributer (not just a viewer) has a really low contribution rate, but that there are a few people that put forth enormous contributions. This doesn't just work for Wikipedia, though -- the economist Pareto discovered this fit a wealth distribution for countries he studied. The interesting thing about this is, with relation to Wikipedia, is that you can't look at just the individual. An "average" user, in the mathematical sense, has contributed very little to the page. You have to look at a page by the group that has worked on it, because it only exists as a result of the group. This explains a number of other online activities: Flickr postings, web blog viewing, e-mail discussion threads. Really cool stuff, and I'm not doing it justice.

The book focuses on what advancements in technology have done, namely, broken down barriers. The cost of organizing people has gone down greatly with the advent of blogs, Facebook, MySpace, Meetup, and any number of other sites. But Shirky doesn't focus on what has been done already; almost quite the opposite. This is what's being done now. Here's the problem people have now, and here's the tools they are using. These tools aren't limited to this problem. Maybe something else will be done using them in the future, who knows? This reminded me a lot of a podcast I heard by Marc Andreessen, co-founder of Ning. Ning is a platform for building social networks, and one of the things Marc mentioned was that they don't try to control what people use it for -- they just enable the community aspect of it. One of Shirky's themes throughout the book was that the internet will change the world the way the printing press did: in an unexpected way. When the printing press came around, the first thought was, "Ok cool, more Bibles." It quickly went far beyond that, to literature, flyers, and newspapers to name but a few. For most of the history of the internet, we've used to to do things online the same way we would in real life. It's just cooler because it's online. Only in recent years have web sites started to harness the power of the internet for what it is, and this is only the tip of the iceberg.

Something that was cool to me was when Shirky mentioned Martin Wattenberg at IBM Research. Martin was the manager of the Many Eyes project that my Extreme Blue team worked with last summer. Martin and crew wrote a paper on visualizing Wikipedia activity. Basically, I felt like a bad ass for sitting on a conference call with him.

It's a great book and a quick read, but chock full of awesomeness.


CBAX 1: Gas Prices

At my girlfriend's suggestion, I'm trying to make this observation into an XKCD:

Luckily, I have a surge check coming in the mail

So yea, apparently, you can make comics that are drawn simpler than XKCD. Also, CBAX stands for "Could Be An XKCD"