Monday, June 27, 2011

How to edit all files containing a particular string

It's often useful to be able to automatically open all files with a particular string (say, to rename a variable throughout your code). To do this with ack, and open all files containing my_string in vim, just type:

vim $(ack -l my_string)

It can be accomplished in a similar way with grep instead of ack.


Edit: If you just want to search and replace a particular string in all files under some directory recursively, use

grep -rl matchstring somedir/ | xargs sed -i "" 's/search string1/search string2/'

It took me a while to find that the double quotes after -i are necessary on Mac OS X. And be aware that the single quotes above usually get mangled to be backticks when copying and pasting.

Edit 2: Don't do this in the root directory of a git repository! It will corrupt the repository.

Saturday, June 25, 2011

More KAUST Beacon photos

The shot of the Beacon in my last post was taken with my iPhone, so last night I went back and got some "real" shots with a tripod and DSLR. Click to see them large, they're better that way.


It's quite a striking structure, up close, especially now that it's fully lit.

Thursday, June 23, 2011

The KAUST Beacon is fully lit

I believe today is the first time:


As a new "House of Wisdom," the University shall be a beacon for peace, hope, and reconciliation...

...this university will become a House of Wisdom to all its peers around the world, a beacon of tolerance.

--King Abdullah

Saturday, June 4, 2011

Mendeley's PDF import has improved dramatically

Looks like the folks at Mendeley have been quietly making some big improvements.

When I first started using Mendeley, I decided to drag a folder of one hundred or so PDFs into it, since it could extract the bibliographic metadata from PDFs. The consequences were disastrous, with a dozen documents named "Society" and all published in "Science". Overall, less than half were correctly imported, and many entries were unrecognizable.

Since then, I don't drag PDFs into Mendeley. This means that bringing in a new document requires a few steps: get the metadata from a journal webpage (automatically using a bookmarklet), download the PDF, and finally associate the PDF to the document.

Today, by accident, I happened to drag a PDF into Mendeley. To my surprise, it was imported perfectly, with all bibliographic data correct. I decided to try another. And a few more. All came in perfectly. I also found that dragging a PDF of a paper already in my library DID NOT create a duplicate.

Thanks, Mendeley developers. Please keep it up.