Difference between revisions of "Ack"

From Christoph's Personal Wiki
Jump to: navigation, search
 
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
==Usage==
 
==Usage==
 
''Note: Taken directly from the official website.''
 
''Note: Taken directly from the official website.''
<pre>
 
$ ack --help
 
Usage: ack [OPTION]... PATTERN [FILES]
 
  
Search for PATTERN in each source file in the tree from cwd on down.
+
*Syntax:
If [FILES] is specified, then only those files/directories are checked.
+
ack [OPTION]... PATTERN [FILES]
ack may also search STDIN, but only if no FILES are specified, or if
+
one of FILES is "-".
+
  
Default switches may be specified in ACK_OPTIONS environment variable or
+
*Help:
an .ackrc file. If you want no dependency on the environment, turn it
+
ack --help
off with --noenv.
+
  
Example: ack -i select
+
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. ack may also search STDIN, but only if no FILES are specified, or if one of FILES is "-".
  
Searching:
+
Default switches may be specified in ACK_OPTIONS environment variable or an <code>.ackrc</code> file. If you want no dependency on the environment, turn it off with --noenv.
  -i, --ignore-case    Ignore case distinctions in PATTERN
+
  -v, --invert-match    Invert match: select non-matching lines
+
  -w, --word-regexp    Force PATTERN to match only whole words
+
  -Q, --literal        Quote all metacharacters; PATTERN is literal
+
  
Search output:
+
Example:
  --line=NUM            Only print line(s) NUM of each file
+
ack -i select
  -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)
+
  --match PATTERN      Specify PATTERN explicitly.
+
  -m, --max-count=NUM  Stop searching in each file after NUM matches
+
  -1                    Stop searching after one match of any kind
+
  -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
+
  
  -A NUM, --after-context=NUM
+
===Searching===
                        Print NUM lines of trailing context after matching
+
;<code>-i, --ignore-case</code> : Ignore case distinctions in PATTERN
                        lines.
+
;<code>-v, --invert-match</code> : Invert match: select non-matching lines
  -B NUM, --before-context=NUM
+
;<code>-w, --word-regexp</code> : Force PATTERN to match only whole words
                        Print NUM lines of leading context before matching
+
;<code>-Q, --literal</code> : Quote all metacharacters; PATTERN is literal
                        lines.
+
  -C [NUM], --context[=NUM]
+
                        Print NUM lines (default 2) of output context.
+
  
   --print0              Print null byte as separator between filenames,
+
===Search output===
                        only works with -f, -g, -l, -L or -c.
+
--line=NUM            Only print line(s) NUM of each file
 +
-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)
 +
--match PATTERN      Specify PATTERN explicitly.
 +
-m, --max-count=NUM   Stop searching in each file after NUM matches
 +
-1                    Stop searching after one match of any kind
 +
-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
 +
-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.
 +
--print0              Print null byte as separator between filenames,
 +
                      only works with -f, -g, -l, -L or -c.
  
File presentation:
+
===File presentation===
  --pager=COMMAND      Pipes all ack output through COMMAND.
+
--pager=COMMAND      Pipes all ack output through COMMAND.
                        Ignored if output is redirected.
+
                      Ignored if output is redirected.
  --nopager            Do not send output through a pager.  Cancels any
+
--nopager            Do not send output through a pager.  Cancels any
                        setting in ~/.ackrc, ACK_PAGER or ACK_PAGER_COLOR.
+
                      setting in ~/.ackrc, ACK_PAGER or ACK_PAGER_COLOR.
  --[no]heading        Print a filename heading above each file's results.
+
--[no]heading        Print a filename heading above each file's results.
                        (default: on when used interactively)
+
                      (default: on when used interactively)
  --[no]break          Print a break between results from different files.
+
--[no]break          Print a break between results from different files.
                        (default: on when used interactively)
+
                      (default: on when used interactively)
  --group              Same as --heading --break
+
--group              Same as --heading --break
  --nogroup            Same as --noheading --nobreak
+
--nogroup            Same as --noheading --nobreak
  --[no]color          Highlight the matching text (default: on unless
+
--[no]color          Highlight the matching text (default: on unless output is redirected, or on Windows)
                        output is redirected, or on Windows)
+
--flush              Flush output immediately, even when ack is used
  --flush              Flush output immediately, even when ack is used
+
                      non-interactively (when output goes to a pipe or file).
                        non-interactively (when output goes to a pipe or
+
                        file).
+
  
File finding:
+
===File finding===
  -f                    Only print the files found, without searching.
+
-f                    Only print the files found, without searching.
                        The PATTERN must not be specified.
+
                      The PATTERN must not be specified.
  -g REGEX              Same as -f, but only print files matching REGEX.
+
-g REGEX              Same as -f, but only print files matching REGEX.
  --sort-files          Sort the found files lexically.
+
--sort-files          Sort the found files lexically.
  
File inclusion/exclusion:
+
===File inclusion/exclusion===
  -a, --all-types      All file types searched;
+
-a, --all-types      All file types searched;
                        Ignores CVS, .svn and other ignored directories
+
                      Ignores CVS, .svn and other ignored directories
  -u, --unrestricted    All files and directories searched
+
-u, --unrestricted    All files and directories searched
  --[no]ignore-dir=name Add/Remove directory from the list of ignored dirs
+
--[no]ignore-dir=name Add/Remove directory from the list of ignored dirs
  -n                    No descending into subdirectories
+
-n                    No descending into subdirectories
  -G REGEX              Only search files that match REGEX
+
-G REGEX              Only search files that match REGEX
 +
--perl                Include only Perl files.
 +
--type=perl          Include only Perl files.
 +
--noperl              Exclude Perl files.
 +
--type=noperl        Exclude Perl files.
 +
                      See "ack --help type" for supported filetypes.
 +
--type-add TYPE=.EXTENSION[,.EXT2[,...]]
 +
                      Files with the given EXTENSION(s) are recognized as
 +
                      being of (the existing) type TYPE
 +
--type-set TYPE=.EXTENSION[,.EXT2[,...]]
 +
                      Files with the given EXTENSION(s) are recognized as
 +
                      being of type TYPE. This replaces an existing
 +
                      definition for type TYPE.
 +
--[no]follow          Follow symlinks.  Default is off.
 +
 +
Directories ignored by default:
 +
  autom4te.cache, blib, _build, .bzr, .cdv, cover_db, CVS, _darcs, ~.dep,
 +
  ~.dot, .git, .hg, ~.nib, .pc, ~.plst, RCS, SCCS, _sgbak and .svn
 +
 +
Files not checked for type:
 +
  /~$/          - Unix backup files
 +
  /#.+#$/        - Emacs swap files
 +
  /[._].*\.swp$/ - Vi(m) swap files
 +
  /core\.\d+$/  - core dumps
  
  --perl                Include only Perl files.
+
===Miscellaneous===
  --type=perl          Include only Perl files.
+
--noenv              Ignore environment variables and ~/.ackrc
  --noperl              Exclude Perl files.
+
--help                This help
  --type=noperl        Exclude Perl files.
+
--man                Man page
                        See "ack --help type" for supported filetypes.
+
--version            Display version & copyright
 +
--thpppt              Bill the Cat
  
  --type-add TYPE=.EXTENSION[,.EXT2[,...]]
+
===Filetypes===
                        Files with the given EXTENSION(s) are recognized as
+
The following is the list of filetypes supported by ack. You can specify a file type with the --type=TYPE format, or the --TYPE
                        being of (the existing) type TYPE
+
format. For example, both --type=perl and --perl work.
  --type-set TYPE=.EXTENSION[,.EXT2[,...]]
+
                        Files with the given EXTENSION(s) are recognized as
+
                        being of type TYPE. This replaces an existing
+
                        definition for type TYPE.
+
  
  --[no]follow          Follow symlinks. Default is off.
+
Note that some extensions may appear in multiple types. For example, .pod files are both Perl and Parrot.
  
  Directories ignored by default:
+
--[no]actionscript .as .mxml
    autom4te.cache, blib, _build, .bzr, .cdv, cover_db, CVS, _darcs, ~.dep,
+
--[no]ada          .ada .adb .ads
    ~.dot, .git, .hg, ~.nib, .pc, ~.plst, RCS, SCCS, _sgbak and .svn
+
  --[no]asm          .asm .s
 
+
--[no]batch        .bat .cmd
  Files not checked for type:
+
--[no]binary      Binary files, as defined by Perl's -B op (default: off)
    /~$/          - Unix backup files
+
--[no]cc          .c .h .xs
    /#.+#$/        - Emacs swap files
+
--[no]cfmx        .cfc .cfm .cfml
    /[._].*\.swp$/ - Vi(m) swap files
+
--[no]clojure      .clj
    /core\.\d+$/  - core dumps
+
--[no]cpp          .cpp .cc .cxx .m .hpp .hh .h .hxx
 
+
--[no]csharp      .cs
Miscellaneous:
+
--[no]css          .css
  --noenv              Ignore environment variables and ~/.ackrc
+
--[no]delphi      .pas .int .dfm .nfm .dof .dpk .dproj .groupproj .bdsgroup .bdsproj
  --help                This help
+
--[no]elisp        .el
  --man                Man page
+
--[no]erlang      .erl .hrl
  --version            Display version & copyright
+
--[no]fortran      .f .f77 .f90 .f95 .f03 .for .ftn .fpp
  --thpppt              Bill the Cat
+
--[no]go          .go
 
+
--[no]groovy      .groovy .gtmpl .gpp .grunit
This is version 1.84 of ack.
+
--[no]haskell      .hs .lhs
 
+
--[no]hh          .h
$ ack --help-types
+
--[no]html        .htm .html .shtml .xhtml
Usage: ack [OPTION]... PATTERN [FILES]
+
--[no]java        .java .properties
 
+
--[no]js          .js
The following is the list of filetypes supported by ack. You can
+
--[no]jsp          .jsp .jspx .jhtm .jhtml
specify a file type with the --type=TYPE format, or the --TYPE
+
--[no]lisp        .lisp .lsp
format.  For example, both --type=perl and --perl work.
+
--[no]lua          .lua
 
+
--[no]make        Makefiles (including *.mk and *.mak)
Note that some extensions may appear in multiple types.  For example,
+
--[no]mason        .mas .mhtml .mpl .mtxt
.pod files are both Perl and Parrot.
+
--[no]objc        .m .h
 
+
--[no]objcpp      .mm .h
    --[no]actionscript .as .mxml
+
--[no]ocaml        .ml .mli
    --[no]asm          .asm .s
+
--[no]parrot      .pir .pasm .pmc .ops .pod .pg .tg
    --[no]batch        .bat .cmd
+
--[no]perl        .pl .pm .pod .t
    --[no]binary      Binary files, as defined by Perl's -B op (default: off)
+
--[no]php          .php .phpt .php3 .php4 .php5 .phtml
    --[no]cc          .c .h .xs
+
--[no]plone        .pt .cpt .metadata .cpy .py
    --[no]cfmx        .cfc .cfm .cfml
+
--[no]python      .py
    --[no]cpp          .cpp .cc .cxx .m .hpp .hh .h .hxx
+
--[no]rake        Rakefiles
    --[no]csharp      .cs
+
--[no]ruby        .rb .rhtml .rjs .rxml .erb .rake .spec
    --[no]css          .css
+
--[no]scala        .scala
    --[no]elisp        .el
+
--[no]scheme      .scm .ss
    --[no]erlang      .erl
+
--[no]shell        .sh .bash .csh .tcsh .ksh .zsh
    --[no]fortran      .f .f77 .f90 .f95 .f03 .for .ftn .fpp
+
--[no]skipped      Files, but not directories, normally skipped by ack (default: off)
    --[no]haskell      .hs .lhs
+
--[no]smalltalk    .st
    --[no]hh          .h
+
--[no]sql          .sql .ctl
    --[no]html        .htm .html .shtml .xhtml
+
--[no]tcl          .tcl .itcl .itk
    --[no]java        .java .properties
+
--[no]tex          .tex .cls .sty
    --[no]js          .js
+
--[no]text        Text files, as defined by Perl's -T op (default: off)
    --[no]jsp          .jsp .jspx .jhtm .jhtml
+
--[no]tt          .tt .tt2 .ttml
    --[no]lisp        .lisp .lsp
+
--[no]vb          .bas .cls .frm .ctl .vb .resx
    --[no]lua          .lua
+
--[no]verilog      .v .vh .sv
    --[no]make        Makefiles
+
--[no]vhdl        .vhd .vhdl
    --[no]mason        .mas .mhtml .mpl .mtxt
+
--[no]vim          .vim
    --[no]objc        .m .h
+
--[no]xml          .xml .dtd .xsl .xslt .ent
    --[no]objcpp      .mm .h
+
--[no]yaml        .yaml .yml
    --[no]ocaml        .ml .mli
+
    --[no]parrot      .pir .pasm .pmc .ops .pod .pg .tg
+
    --[no]perl        .pl .pm .pod .t
+
    --[no]php          .php .phpt .php3 .php4 .php5
+
    --[no]plone        .pt .cpt .metadata .cpy .py
+
    --[no]python      .py
+
    --[no]ruby        .rb .rhtml .rjs .rxml .erb
+
    --[no]scheme      .scm
+
    --[no]shell        .sh .bash .csh .tcsh .ksh .zsh
+
    --[no]skipped      Files, but not directories, normally skipped by ack (default: off)
+
    --[no]smalltalk    .st
+
    --[no]sql          .sql .ctl
+
    --[no]tcl          .tcl .itcl .itk
+
    --[no]tex          .tex .cls .sty
+
    --[no]text        Text files, as defined by Perl's -T op (default: off)
+
    --[no]tt          .tt .tt2 .ttml
+
    --[no]vb          .bas .cls .frm .ctl .vb .resx
+
    --[no]vim          .vim
+
    --[no]xml          .xml .dtd .xslt .ent
+
    --[no]yaml        .yaml .yml
+
</pre>
+
  
 
==External links==
 
==External links==
*[http://petdance.com/ack/ official website]
+
*[http://betterthangrep.com/ official website]
 
*[http://blog.i-no.de/archives/2008/05/06/index.html ack examples]
 
*[http://blog.i-no.de/archives/2008/05/06/index.html ack examples]
 +
*[http://stevengharms.com/blog/2012/04/10/use-ack-instead-of-grep-to-parse-text-files/ Use Ack Instead of Grep to Parse Text Files] &mdash; by Steven Harms
  
 
[[Category:Linux Command Line Tools]]
 
[[Category:Linux Command Line Tools]]

Latest revision as of 00:03, 16 December 2012

ack is a tool like grep, aimed at programmers with large trees of heterogeneous source code. ack is written purely in Perl, and takes advantage of the power of Perl's regular expressions.

Usage

Note: Taken directly from the official website.

  • Syntax:
ack [OPTION]... PATTERN [FILES]
  • Help:
ack --help

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. ack may also search STDIN, but only if no FILES are specified, or if one of FILES is "-".

Default switches may be specified in ACK_OPTIONS environment variable or an .ackrc file. If you want no dependency on the environment, turn it off with --noenv.

Example:

ack -i select

Searching

-i, --ignore-case 
Ignore case distinctions in PATTERN
-v, --invert-match 
Invert match: select non-matching lines
-w, --word-regexp 
Force PATTERN to match only whole words
-Q, --literal 
Quote all metacharacters; PATTERN is literal

Search output

--line=NUM            Only print line(s) NUM of each file
-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)
--match PATTERN       Specify PATTERN explicitly.
-m, --max-count=NUM   Stop searching in each file after NUM matches
-1                    Stop searching after one match of any kind
-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
-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.
--print0              Print null byte as separator between filenames,
                      only works with -f, -g, -l, -L or -c.

File presentation

--pager=COMMAND       Pipes all ack output through COMMAND.
                      Ignored if output is redirected.
--nopager             Do not send output through a pager.  Cancels any
                      setting in ~/.ackrc, ACK_PAGER or ACK_PAGER_COLOR.
--[no]heading         Print a filename heading above each file's results.
                      (default: on when used interactively)
--[no]break           Print a break between results from different files.
                      (default: on when used interactively)
--group               Same as --heading --break
--nogroup             Same as --noheading --nobreak
--[no]color           Highlight the matching text (default: on unless output is redirected, or on Windows)
--flush               Flush output immediately, even when ack is used
                      non-interactively (when output goes to a pipe or file).

File finding

-f                    Only print the files found, without searching.
                      The PATTERN must not be specified.
-g REGEX              Same as -f, but only print files matching REGEX.
--sort-files          Sort the found files lexically.

File inclusion/exclusion

-a, --all-types       All file types searched;
                      Ignores CVS, .svn and other ignored directories
-u, --unrestricted    All files and directories searched
--[no]ignore-dir=name Add/Remove directory from the list of ignored dirs
-n                    No descending into subdirectories
-G REGEX              Only search files that match REGEX
--perl                Include only Perl files.
--type=perl           Include only Perl files.
--noperl              Exclude Perl files.
--type=noperl         Exclude Perl files.
                      See "ack --help type" for supported filetypes.
--type-add TYPE=.EXTENSION[,.EXT2[,...]]
                      Files with the given EXTENSION(s) are recognized as
                      being of (the existing) type TYPE
--type-set TYPE=.EXTENSION[,.EXT2[,...]]
                      Files with the given EXTENSION(s) are recognized as
                      being of type TYPE. This replaces an existing
                      definition for type TYPE.
--[no]follow          Follow symlinks.  Default is off.

Directories ignored by default:
  autom4te.cache, blib, _build, .bzr, .cdv, cover_db, CVS, _darcs, ~.dep,
  ~.dot, .git, .hg, ~.nib, .pc, ~.plst, RCS, SCCS, _sgbak and .svn

Files not checked for type:
  /~$/           - Unix backup files
  /#.+#$/        - Emacs swap files
  /[._].*\.swp$/ - Vi(m) swap files
  /core\.\d+$/   - core dumps

Miscellaneous

--noenv               Ignore environment variables and ~/.ackrc
--help                This help
--man                 Man page
--version             Display version & copyright
--thpppt              Bill the Cat

Filetypes

The following is the list of filetypes supported by ack. You can specify a file type with the --type=TYPE format, or the --TYPE format. For example, both --type=perl and --perl work.

Note that some extensions may appear in multiple types. For example, .pod files are both Perl and Parrot.

--[no]actionscript .as .mxml
--[no]ada          .ada .adb .ads
--[no]asm          .asm .s
--[no]batch        .bat .cmd
--[no]binary       Binary files, as defined by Perl's -B op (default: off)
--[no]cc           .c .h .xs
--[no]cfmx         .cfc .cfm .cfml
--[no]clojure      .clj
--[no]cpp          .cpp .cc .cxx .m .hpp .hh .h .hxx
--[no]csharp       .cs
--[no]css          .css
--[no]delphi       .pas .int .dfm .nfm .dof .dpk .dproj .groupproj .bdsgroup .bdsproj
--[no]elisp        .el
--[no]erlang       .erl .hrl
--[no]fortran      .f .f77 .f90 .f95 .f03 .for .ftn .fpp
--[no]go           .go
--[no]groovy       .groovy .gtmpl .gpp .grunit
--[no]haskell      .hs .lhs
--[no]hh           .h
--[no]html         .htm .html .shtml .xhtml
--[no]java         .java .properties
--[no]js           .js
--[no]jsp          .jsp .jspx .jhtm .jhtml
--[no]lisp         .lisp .lsp
--[no]lua          .lua
--[no]make         Makefiles (including *.mk and *.mak)
--[no]mason        .mas .mhtml .mpl .mtxt
--[no]objc         .m .h
--[no]objcpp       .mm .h
--[no]ocaml        .ml .mli
--[no]parrot       .pir .pasm .pmc .ops .pod .pg .tg
--[no]perl         .pl .pm .pod .t
--[no]php          .php .phpt .php3 .php4 .php5 .phtml
--[no]plone        .pt .cpt .metadata .cpy .py
--[no]python       .py
--[no]rake         Rakefiles
--[no]ruby         .rb .rhtml .rjs .rxml .erb .rake .spec
--[no]scala        .scala
--[no]scheme       .scm .ss
--[no]shell        .sh .bash .csh .tcsh .ksh .zsh
--[no]skipped      Files, but not directories, normally skipped by ack (default: off)
--[no]smalltalk    .st
--[no]sql          .sql .ctl
--[no]tcl          .tcl .itcl .itk
--[no]tex          .tex .cls .sty
--[no]text         Text files, as defined by Perl's -T op (default: off)
--[no]tt           .tt .tt2 .ttml
--[no]vb           .bas .cls .frm .ctl .vb .resx
--[no]verilog      .v .vh .sv
--[no]vhdl         .vhd .vhdl
--[no]vim          .vim
--[no]xml          .xml .dtd .xsl .xslt .ent
--[no]yaml         .yaml .yml

External links