grep snippets

Colorize grep

Tagged grep, bash, color, linux  Languages bash

Put this export in .bashrc to make grep colorize the text it found.

export GREP_OPTIONS='--color=auto'

How to read and grep compressed & rotated log files

Tagged zgrep, zless, logs, apache, grep  Languages bash

Your typical server log directory looks something like this:

access.log
access.log.1
access.log.1.gz
access.log.2.gz

Now what if you want to extract data from day x to day y? You could use gzip and grep to uncompress the files, but there's a better way: the z commands.

All you have to do is:

zgrep "2010" /var/log/apache2/access.log*

More info on the subject can be found here: http://www.thegeekstuff.com/2009/05/zcat-zless-zgrep-zdiff-zcmp-zmore-gzip-file-operations-on-the-compressed-files/

How to fix "command not found:  grep" on OSX

Tagged key bindings, alt, space, whitespace, ruby, grep  Languages bash

This issue will bite everyone who touches a keyboard. This fixes, e.g., the following issues: * command not found:  grep (Shell) * undefined local variable or method (Ruby) *

First, do this:

mkdir -p ~/Library/KeyBindings/
vim ~/Library/KeyBindings/DefaultKeyBinding.dict

Then paste this:

{
  "~ " = ("insertText:", " ");
}

Save the file.

Quit and reopen applications to apply the new key bindings in DefaultKeyBinding.dict.

References

http://osxnotes.net/keybindings.html http://linuxtoosx.blogspot.fi/2010/10/disabling-option-space-and-altgr-space.html

MacVim

For MacVim i have yet to find a solution for insert mode, so just use vim in the terminal...