@pindex msggrep
@cindex @code{msggrep} program, usage
@example
msggrep [@var{option}] [@var{inputfile}]
@end example

@cindex search messages in a catalog
The @code{msggrep} program extracts all messages of a translation catalog
that match a given pattern or belong to some given source files.

@subsection Input file location

@table @samp
@item @var{inputfile}
Input PO file.

@item -D @var{directory}
@itemx --directory=@var{directory}
@opindex -D@r{, @code{msggrep} option}
@opindex --directory@r{, @code{msggrep} option}
Add @var{directory} to the list of directories.  Source files are
searched relative to this list of directories.  The resulting @file{.po}
file will be written relative to the current directory, though.

@end table

If no @var{inputfile} is given or if it is @samp{-}, standard input is read.

@subsection Output file location

@table @samp
@item -o @var{file}
@itemx --output-file=@var{file}
@opindex -o@r{, @code{msggrep} option}
@opindex --output-file@r{, @code{msggrep} option}
Write output to specified file.

@end table

The results are written to standard output if no output file is specified
or if it is @samp{-}.

@subsection Message selection

@example
  [-N @var{sourcefile}]... [-M @var{domainname}]...
  [-J @var{msgctxt-pattern}] [-K @var{msgid-pattern}] [-T @var{msgstr-pattern}]
  [-C @var{comment-pattern}]
@end example

A message is selected if
@itemize @bullet
@item it comes from one of the specified source files,
@item or if it comes from one of the specified domains,
@item or if @samp{-J} is given and its context (msgctxt) matches
@var{msgctxt-pattern},
@item or if @samp{-K} is given and its key (msgid or msgid_plural) matches
@var{msgid-pattern},
@item or if @samp{-T} is given and its translation (msgstr) matches
@var{msgstr-pattern},
@item or if @samp{-C} is given and the translator's comment matches
@var{comment-pattern}.
@end itemize

When more than one selection criterion is specified, the set of selected
messages is the union of the selected messages of each criterion.

@var{msgctxt-pattern} or @var{msgid-pattern} or @var{msgstr-pattern} syntax:
@example
  [-E | -F] [-e @var{pattern} | -f @var{file}]...
@end example
@var{pattern}s are basic regular expressions by default, or extended regular
expressions if -E is given, or fixed strings if -F is given.

@table @samp
@item -N @var{sourcefile}
@itemx --location=@var{sourcefile}
@opindex -N@r{, @code{msggrep} option}
@opindex --location@r{, @code{msggrep} option}
Select messages extracted from @var{sourcefile}.  @var{sourcefile} can be
either a literal file name or a wildcard pattern.

@item -M @var{domainname}
@itemx --domain=@var{domainname}
@opindex -M@r{, @code{msggrep} option}
@opindex --domain@r{, @code{msggrep} option}
Select messages belonging to domain @var{domainname}.

@item -J
@itemx --msgctxt
@opindex -J@r{, @code{msggrep} option}
@opindex --msgctxt@r{, @code{msggrep} option}
Start of patterns for the msgctxt.

@item -K
@itemx --msgid
@opindex -K@r{, @code{msggrep} option}
@opindex --msgid@r{, @code{msggrep} option}
Start of patterns for the msgid.

@item -T
@itemx --msgstr
@opindex -T@r{, @code{msggrep} option}
@opindex --msgstr@r{, @code{msggrep} option}
Start of patterns for the msgstr.

@item -C
@itemx --comment
@opindex -C@r{, @code{msggrep} option}
@opindex --comment@r{, @code{msggrep} option}
Start of patterns for the translator's comment.

@item -X
@itemx --extracted-comment
@opindex -X@r{, @code{msggrep} option}
@opindex --extracted-comment@r{, @code{msggrep} option}
Start of patterns for the extracted comments.

@item -E
@itemx --extended-regexp
@opindex -E@r{, @code{msggrep} option}
@opindex --extended-regexp@r{, @code{msggrep} option}
Specify that @var{pattern} is an extended regular expression.

@item -F
@itemx --fixed-strings
@opindex -F@r{, @code{msggrep} option}
@opindex --fixed-strings@r{, @code{msggrep} option}
Specify that @var{pattern} is a set of newline-separated strings.

@item -e @var{pattern}
@itemx --regexp=@var{pattern}
@opindex -e@r{, @code{msggrep} option}
@opindex --regexp=@r{, @code{msggrep} option}
Use @var{pattern} as a regular expression.

@item -f @var{file}
@itemx --file=@var{file}
@opindex -f@r{, @code{msggrep} option}
@opindex --file@r{, @code{msggrep} option}
Obtain @var{pattern} from @var{file}.

@item -i
@itemx --ignore-case
@opindex -i@r{, @code{msggrep} option}
@opindex --ignore-case@r{, @code{msggrep} option}
Ignore case distinctions.

@item -v
@itemx --invert-match
@opindex -v@r{, @code{msggrep} option}
@opindex --invert-match@r{, @code{msggrep} option}
Output only the messages that do not match any selection criterion, instead
of the messages that match a selection criterion.

@end table

@subsection Input file syntax

@table @samp
@item -P
@itemx --properties-input
@opindex -P@r{, @code{msggrep} option}
@opindex --properties-input@r{, @code{msggrep} option}
Assume the input file is a Java ResourceBundle in Java @code{.properties}
syntax, not in PO file syntax.

@item --stringtable-input
@opindex --stringtable-input@r{, @code{msggrep} option}
Assume the input file is a NeXTstep/GNUstep localized resource file in
@code{.strings} syntax, not in PO file syntax.

@end table

@subsection Output details

@c --no-escape and --escape omitted on purpose.  They are not useful.

@table @samp
@item --color
@itemx --color=@var{when}
@opindex --color@r{, @code{msggrep} option}
Specify whether or when to use colors and other text attributes.
See @ref{The --color option} for details.

@item --style=@var{style_file}
@opindex --style@r{, @code{msggrep} option}
Specify the CSS style rule file to use for @code{--color}.
See @ref{The --style option} for details.

@item --force-po
@opindex --force-po@r{, @code{msggrep} option}
Always write an output file even if it contains no message.

@item --indent
@opindex --indent@r{, @code{msggrep} option}
Write the .po file using indented style.

@item --no-location
@opindex --no-location@r{, @code{msggrep} option}
Do not write @samp{#: @var{filename}:@var{line}} lines.

@item -n
@itemx --add-location=@var{type}
@opindex --add-location@r{, @code{msggrep} option}
Generate @samp{#: @var{filename}:@var{line}} lines (default).

The optional @var{type} can be either @samp{full}, @samp{file}, or
@samp{never}.  If it is not given or @samp{full}, it generates the
lines with both file name and line number.  If it is @samp{file}, the
line number part is omitted.  If it is @samp{never}, it completely
suppresses the lines (same as @code{--no-location}).

@item --strict
@opindex --strict@r{, @code{msggrep} option}
Write out a strict Uniforum conforming PO file.  Note that this
Uniforum format should be avoided because it doesn't support the
GNU extensions.

@item -p
@itemx --properties-output
@opindex -p@r{, @code{msggrep} option}
@opindex --properties-output@r{, @code{msggrep} option}
Write out a Java ResourceBundle in Java @code{.properties} syntax.  Note
that this file format doesn't support plural forms and silently drops
obsolete messages.

@item --stringtable-output
@opindex --stringtable-output@r{, @code{msggrep} option}
Write out a NeXTstep/GNUstep localized resource file in @code{.strings} syntax.
Note that this file format doesn't support plural forms.

@item -w @var{number}
@itemx --width=@var{number}
@opindex -w@r{, @code{msggrep} option}
@opindex --width@r{, @code{msggrep} option}
Set the output page width.  Long strings in the output files will be
split across multiple lines in order to ensure that each line's width
(= number of screen columns) is less or equal to the given @var{number}.

@item --no-wrap
@opindex --no-wrap@r{, @code{msggrep} option}
Do not break long message lines.  Message lines whose width exceeds the
output page width will not be split into several lines.  Only file reference
lines which are wider than the output page width will be split.

@item --sort-output
@opindex --sort-output@r{, @code{msggrep} option}
Generate sorted output.  Note that using this option makes it much harder
for the translator to understand each message's context.

@item --sort-by-file
@opindex --sort-by-file@r{, @code{msggrep} option}
Sort output by file location.

@end table

@subsection Informative output

@table @samp
@item -h
@itemx --help
@opindex -h@r{, @code{msggrep} option}
@opindex --help@r{, @code{msggrep} option}
Display this help and exit.

@item -V
@itemx --version
@opindex -V@r{, @code{msggrep} option}
@opindex --version@r{, @code{msggrep} option}
Output version information and exit.

@end table

@subsection Examples

To extract the messages that come from the source files
@code{gnulib-lib/error.c} and @code{gnulib-lib/getopt.c}:

@smallexample
msggrep -N gnulib-lib/error.c -N gnulib-lib/getopt.c input.po
@end smallexample

To extract the messages that contain the string ``Please specify'' in the
original string:

@smallexample
msggrep --msgid -F -e 'Please specify' input.po
@end smallexample

To extract the messages that have a context specifier of either ``Menu>File''
or ``Menu>Edit'' or a submenu of them:

@smallexample
msggrep --msgctxt -E -e '^Menu>(File|Edit)' input.po
@end smallexample

To extract the messages whose translation contains one of the strings in the
file @code{wordlist.txt}:

@smallexample
msggrep --msgstr -F -f wordlist.txt input.po
@end smallexample
