LinuxCommandLibrary

srgn

Syntax-aware grep and code editing tool

TLDR

Replace matching text
$ echo 'Hello World!' | srgn '[wW]orld' -- 'there'
copy
Search within Python class definitions
$ srgn --python 'class' '[age]'
copy
Convert piped input to uppercase
$ echo 'hello' | srgn --upper '.*'
copy

SYNOPSIS

srgn [--language] [--action] [scope] [-- replacement]

DESCRIPTION

srgn is a grep-like tool that understands source code syntax via tree-sitter and allows manipulation in addition to search. It combines capabilities of tr, sed, and ripgrep with language grammar awareness, supporting Python, Rust, Go, TypeScript, C, C#, and HCL. It can perform bulk file edits, case transformations, and regex replacements scoped to specific syntactic constructs.

HISTORY

srgn was created by Alex Povel and is written in Rust.

SEE ALSO

ripgrep(1), sed(1), ast-grep(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard