Jump to content

Manual:grep.php

From mediawiki.org
MediaWiki version:
1.38

Details

[edit]

grep.php file is a maintenance script that searches the source text of pages for lines matching a given regex, and prints the matching lines to stdout.

This script first fetches all page titles from the database, optionally filtering them by namespace or prefix, and then fetches their text contents to check for the given PCRE regular expression, printing the matching lines.

Options/arguments

[edit]
Option/Argument Description Required?
regex The regex to search for. Required
--prefix Title prefix. Can be specified more than once. Use e.g. --prefix=Talk: to search an entire namespace. Optional
--show-wiki
-l
Add the wiki ID to the output Optional
--pages-with-matches Suppress normal output; instead print the title of each page from which output would normally have been printed. Optional

Usage

[edit]
php maintenance/grep.php <regexp> [ --prefix | --show-wiki | pages-with-matches ]

The regular expression will be fed directly to preg_replace(), delimited by curly braces, except if the first character is /, in which case you are expected to add the end delimiter. This allows providing a regular expression modifier after the end delimiter.

[edit]