Gå til hovedinnhold

kgrep

Search the human-readable text inside any supported format for a regular expression — the prose of a Word .docx, the values of a JSON catalog, the segments of an XLIFF file — skipping markup and structure. Output mirrors grep: one matching block per line, optionally prefixed with the file name and the block number.

kgrep [flags] PATTERN [FILE...]

The pattern is a Go regular expression. With no file, or when the file is -, standard input is read. Exit status is 0 if any block matched, 1 if none did, 2 on error — the same convention as grep, so kgrep composes in shell conditionals.

Examples

# Find a word inside a Word document
kgrep "Tervetuloa" report.docx

# Case-insensitive search across JSON catalogs
kgrep -i todo locales/*.json

# Recurse a content tree, searching French translations
kgrep -r --target fr "déconnexion" ./content

# Count occurrences per file
kgrep -c "©" *.md

# Use kgrep's exit status in a script
if kgrep -q "DRAFT" manual.docx; then
echo "manual still contains a DRAFT marker"
fi

Options

FlagMeaning
-i, --ignore-caseCase-insensitive matching.
-v, --invert-matchSelect blocks that do not match.
-c, --countPrint a count of matching blocks per file.
-n, --line-numberPrefix each match with its block number.
-o, --only-matchingPrint only the matched text, not the whole block.
-l, --files-with-matchesPrint only the names of files containing matches.
-L, --files-without-matchPrint only the names of files with no match.
-w, --word-regexpMatch only whole words.
-F, --fixed-stringsTreat the pattern as a literal string, not a regexp.
-r, --recursiveRecurse into directory arguments.
-H, --with-filenamePrint the file name for each match.
--no-filenameSuppress file-name prefixes.
-e, --regexp PATTERNAdd a pattern (repeatable); a block matches if any matches.
-q, --quietSuppress output; report the result through exit status only.
--color MODEHighlight matches: auto, always, never.
--target LOCALESearch the translation for LOCALE instead of the source.
--source-lang LOCALESource language of the content (default en).
-f, --formatOverride format detection (e.g. -f json).
--encoding NAMEInput encoding (default UTF-8).
--jsonEmit matches as JSON.