Q:

Copy last few lines of file to clipboard

I’m trying to copy just the last few lines of a file to my clipboard on Mac OS X using something like pbcopy (but obviously pbcopy just copies the entire contents).
Use case for this is, I have a really large log file and I only want to copy the last few lines (e.g. last 5 lines) to my clipboard to find out what happened recently.
This needs to be keyboard driven so I can execute it fast.
Don’t mind if it’s an AppleScript or Shell script.

A:

I just tried this out using OS X and it worked. It copies the last 5 lines of a log file to the clipboard. Bind it to a hotkey and you should be set.
tail -5 'somefile.log' | pbcopy

For binding terminal commands to hotkeys, you can probably use automator.app, or download Platypus to generate an .app out of the above script. You can then go into your keyboard settings in System Preferences and set up the binding.

