reference Flags

--text-output

Accepted by
opengrep scan, opengrep ci
Value
FILE
See also
--text, --output

Writes the text output to FILE, in addition to the output on standard output.

The file contains color codes only when color is forced, by --force-color or OPENGREP_FORCE_COLOR. The flag can be repeated to write several files. The file is written even when the scan finds nothing; it is then empty.

Examples

JSON on screen, text in a file

rule.yaml
rules:  - id: find-eval    pattern: eval(...)    message: found eval    languages: [python]    severity: WARNING
app.py
eval(1)
Command and result
$ opengrep scan --config rule.yaml --json --text-output report.txt app.py 2>/dev/null | jq .
{
  "version": "X.Y.Z",
  "results": [
    {
      "check_id": "find-eval",
      "path": "app.py",
      "start": {
        "line": 1,
        "col": 1,
        "offset": 0
      },
      "end": {
        "line": 1,
        "col": 8,
        "offset": 7
      },
      "extra": {
        "metavars": {},
        "message": "found eval",
        "metadata": {},
        "severity": "WARNING",
        "fingerprint": "cc2ee9ac3b87e874db7ede72562f586db0607e44a6ebc8879fc1772bd2699a2f302d90e0cf6bde9dce450cb0891646fb0b3d70263351681e1d2e48ca0d26d960_0",
        "lines": "eval(1)",
        "is_ignored": false,
        "validation_state": "NO_VALIDATOR",
        "engine_kind": "Opengrep"
      }
    }
  ],
  "errors": [],
  "paths": {
    "scanned": [
      "app.py"
    ]
  },
  "interfile_languages_used": [],
  "skipped_rules": []
}
$ cat report.txt
app.py

  warn  find-eval
  found eval

     1: eval(1)
$ grep -c $'\x1b' report.txt
0
$ opengrep scan --config rule.yaml --force-color --text-output report.txt app.py > /dev/null 2>&1
$ grep -c $'\x1b' report.txt
3

The grep commands count the lines with a color code in the file: none at first, and three once color is forced.