*nix

Grepping around the match

Posted in *nix on June 2nd, 2010 by Marcelo de Moraes Serpa – Be the first to comment

So, you want to dig into your huge logfile, you know that the information you are searching contains a piece of data, but you also want the context around it. Definetly not good to load the entire log file into memory, if it’s too big. Also, not very convenient to search manually using an editor. What do you do?

Use grep:


$ grep /path/to/file -An -Bn

Where n is an integer. -A specifies the number of lines to be printed after the match, and B does for the lines before, as you might have guessed.

Pretty useful.

Using emacs from the CLI on OSX

Posted in *nix, Uncategorized on May 27th, 2010 by Marcelo de Moraes Serpa – Be the first to comment

If you are compiling emacs from source on OSX (which you should be doing) or even if you are using a pre-packaged version from emacsformacosx, you might be asking yourself why you can’t run emacs from the CLI.

I didn’t have time to dig into the whys of it, but it has to do with the Emacs binari not finding some resources because of the use of relative paths.

Anyway, I’ve came up with a very simple solution. Just create a executable file with the following contents:


/Applications/Emacs.app/Contents/MacOS/Emacs $@

The $@ will delegate command line arguments passed to this script to the Emacs binary.

Make it executable (chmod +x emacs) and put it on any directory that is part of your PATH, and now you should be good to go.

This is quite useful to, for example, run emacs with –debug-init or any other CLI use for that matter.