Thursday, April 05, 2007

Find Grep And Vi Keys Small Memo

I tend to forget this now and then to grep on a specific list of files:

find . -name "*.xml" | xargs grep "iwantthis"

And I also tend to forget the vi keys. Small extract:

h - move left one character
j - move down one line
k - move up
l - move right
$ - go to the end of the current line
0 - go to the beginning of the current line
G - go to the last line in the file
15G - go to line 15
control-F - forward one page
control-B - backwards one page
n (N) - next (previous) in search mode (/ or ? forward or backward)
s/OLD/NEW/g - replace on current line
%s/OLD/NEW/g - replace every occurence in file (or use 0,$ instead of %)

x - delete one character

Update I have to add the standard replace in multiple files via sed command. Here is an example of how to move your eclipse workspace to another directory:
  • find . -name "*.xml" | xargs sed -i "s,c:[/\\]java[/\\]eclipse,d:/eclipse302,gi"


  1. I hear you. Here's my little script I put in my ~/bin dir:

    file: findIn
    # usage findIn [file pattern] [search string]
    find -name "$1"|xargs grep $2

    were it not for shortcuts like that I'd go insane.

  2. I always use:

    find . -name *.html -exec grep -H {} \;

    hehe, incase you are interested ;-)