Vai al contenuto principale
kitlocal.dev

Cheatsheet Text CLI (grep / sed / awk)

Esecuzione locale

Elaborazione al 100% nel tuo browser. Input e output non lasciano mai il tuo dispositivo.

Comandi Unix di elaborazione testi con pipeline reali: ricerca con GNU grep/ripgrep, modifica flussi con sed, campi e aggregazioni con awk, più cut, sort, uniq e tr.

Come funziona

Unix text tools act like stream filters: each tool reads lines from files or stdin, does one small job (search, slice columns, replace, count, sort) and writes lines to stdout so you can snap them together with `|`.

Kit di sopravvivenza

I pochi comandi da imparare per primi.

41 comandi

Scorciatoie da tastiera/Attiva ricercaJKSposta selezioneCCopia selezionatoFAggiungi selezionato ai segnalibriEscCancella ricerca

Search lines (grep)

grep prints lines matching a pattern. Add -n for line numbers, -i for case-insensitive and -E for extended regex.

Documentazione ufficiale: grep usage
  • Essenziale

    Search recursively and print file paths and line numbers.

    grep -rn "<pattern>" <dir>

    Componi il comando

    grep -rn "<pattern>" <dir>

    I valori vengono inseriti esattamente come li digiti. Racchiudili tra virgolette se contengono spazi o caratteri speciali.

    Quando usarlo

    Find every occurrence of a function, error code or config key across a directory tree.

    Dettaglio

    -r
    recurse into subdirectories
    -n
    prefix matches with 1-based line numbers
    <pattern>
    search regex or text
    <dir>
    directory to search (use `.` for current)

    Esempio

    printf "200 GET /api\n500 POST /pay\n200 GET /api\n404 GET /old\n" | grep -n "GET"

    Risultato

    1:200 GET /api
    3:200 GET /api
    4:404 GET /old

    Funziona anche

    • rg "<pattern>" (ripgrep, skips .gitignore automatically)

    Vedi anche

Transform text streams (sed)

sed edits lines on the fly. Test without `-i` first so you preview changes on stdout before modifying files.

Documentazione ufficiale: sed commands

Process columns & aggregate (awk)

awk splits every line into fields ($1, $2, ...) automatically, running `{ action }` whenever `condition` is true.

Documentazione ufficiale: GNU Awk User Guide

Sort, count, cut & translate

Fast single-purpose coreutils for frequency counts, column slicing and character cleanup.

Documentazione ufficiale: Operating on sorted files

Find files & batch commands (find, xargs)

Locate files by name, size or age and pass them safely to downstream commands using NUL delimiters.

Documentazione ufficiale: GNU Findutils Manual

Provalo in uno strumento di KitLocal

Glossario
stdin / stdout
Standard input and output streams wired together by pipes (`|`).
ERE (-E)
Extended Regular Expressions: `+`, `?`, `|`, `()` work without extra backslashes.
Field ($1, $NF)
In awk, columns split by whitespace (or `-F`): `$0` is the whole line, `$NF` is the last column.
NUL delimiter (-0)
Separating paths with `\0` instead of newlines so spaces and quotes never break pipelines.

Verificato il 15 nov 2026 · Verificato sulla versione GNU grep 3.12 / sed 4.9 / gawk 5.3

Fonti: GNU Coreutils Manual · GNU grep Manual · GNU sed Manual · GNU Awk Manual

Sostituisci gli elementi tra parentesi angolari con i tuoi valori. I comandi provengono dalla documentazione ufficiale e gli esempi sono stati eseguiti sulla versione indicata.