{
    "mode": "perldoc",
    "parameter": "grep",
    "section": "-f",
    "url": "https://www.chedong.com/phpMan.php/perldoc/grep/json",
    "generated": "2026-06-03T04:24:05Z",
    "sections": [],
    "flags": [],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Find patterns in files using `regex`es.",
        "examples": [
            {
                "description": "Search for a pattern within files",
                "command": "grep \"{{search_pattern}}\" {{path/to/file1 path/to/file2 ...}}"
            },
            {
                "description": "Search for an exact string (disables `regex`es)",
                "command": "grep {{-F|--fixed-strings}} \"{{exact_string}}\" {{path/to/file}}"
            },
            {
                "description": "Search for a pattern in all files recursively in a directory, ignoring binary files",
                "command": "grep {{-rI|--recursive --binary-files=without-match}} \"{{search_pattern}}\" {{path/to/directory}}"
            },
            {
                "description": "Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match",
                "command": "grep {{-context|--before-context|--after-context}} 3 \"{{search_pattern}}\" {{path/to/file}}"
            },
            {
                "description": "Print file name and line number for each match with color output",
                "command": "grep {{-Hn|--with-filename --line-number}} --color=always \"{{search_pattern}}\" {{path/to/file}}"
            },
            {
                "description": "Print only the matched text",
                "command": "grep {{-o|--only-matching}} \"{{search_pattern}}\" {{path/to/file}}"
            },
            {
                "description": "Read data from `stdin` and do not print lines that match a pattern",
                "command": "cat {{path/to/file}} | grep {{-v|--invert-match}} \"{{search_pattern}}\""
            },
            {
                "description": "Use extended `regex`es (supports `?`, `+`, `{}`, `()`, and `|`), in case-insensitive mode",
                "command": "grep {{-Ei|--extended-regexp --ignore-case}} \"{{search_pattern}}\" {{path/to/file}}"
            }
        ]
    }
}