ツール > rak

概説

  • Ruby版grep
  • デフォルトで、.svn.cvsを無視して検索してくれる
  • grepが無いwindowsとかで使うと便利
    • linuxだと色分けをしてくれるらしい

インストール

  • gem install rak

使い方

  • rak hoge ./temp.txt
    • temp.txtの中でhogeという文字列が含まれている行数を表示する
  • rak hoge
    • カレントディレクトリ以下でhogeという文字列が含まれているファイルと行数を表示する
  • rak hoge --ruby
    • .rbファイルについて検索する
  • rak hoge --noruby
    • .rbファイル以外について検索する

オプション多数

- option
Usage: rak [OPTION]... PATTERN [FILES]
 
Search for PATTERN in each source file in the tree from cwd on down.
If [FILES] is specified, then only those files/directories are checked.
rak will search STDIN only if no FILES are specified.
 
Example: rak -i select
 
Searching:
  -i, --ignore-case     Ignore case distinctions
  -v, --invert-match    Invert match: select non-matching lines
  -w, --word-regexp     Force PATTERN to match only whole words
  -x, --line-regexp     Force PATTERN to match only whole lines
  -Q, --literal         Quote all metacharacters; expr is literal
  -s, --line-start      Match only at the start of a line
  -e, --line-start      Match only at the end of a line
 
Search output:
  -l, --files-with-matches
                        Only print filenames containing matches
  -L, --files-without-match
                        Only print filenames with no match
  -o                    Show only the part of a line matching PATTERN
                        (turns off text highlighting)
  --passthru            Print all lines, whether matching or not
  --output=expr         Output the evaluation of expr for each line
                        (turns off text highlighting)
  -m, --max-count=NUM   Stop searching in a file after NUM matches
  -H, --with-filename   Print the filename for each match
  -h, --no-filename     Suppress the prefixing filename on output
  -c, --count           Show number of lines matching per file
 
  --group               Group matches by file name.
                        (default: on when used interactively)
  --nogroup             One result per line, including filename, like grep
                        (default: on when the output is redirected)
 
  --[no]colour          Highlight the matching text (default: on unless
                        output is redirected, or on Windows)
 
  -A NUM, --after-context=NUM
                        Print NUM lines of trailing context after matching
                        lines.
  -B NUM, --before-context=NUM
                        Print NUM lines of leading context before matching
                        lines.
  -C [NUM], --context[=NUM]
                        Print NUM lines (default 2) of output context.
 
File finding:
  -f                    Only print the files found, without searching.
                        The PATTERN must not be specified.
  --sort-files          Sort the found files lexically.
 
File inclusion/exclusion:
  -n                    No descending into subdirectories
  -g REGEX              Only search in file matching REGEX.
  -a, --all             All files, regardless of extension (but still skips
                        blib, pkg, CVS, _darcs, .git, .pc, RCS, SCCS and .svn di
rs)
  --ruby                Include only Ruby files.
  --type=ruby           Include only Ruby files.
  --noruby              Exclude Ruby files.
  --type=noruby         Exclude Ruby files.
                        See "rak --help type" for supported filetypes.
  --[no]follow          Follow symlinks.  Default is off.
 
Miscellaneous:
  --help                This help
  --version             Display version & copyright
 

解説サイト

最終更新:2008年07月01日 22:14