본문으로 바로 가기
kitlocal.dev

Text CLI (grep / sed / awk) 치트시트

로컬에서 실행

100% 브라우저에서 처리됩니다. 입력과 출력이 기기 밖으로 나가지 않습니다.

실제 파이프라인으로 배우는 Unix 텍스트 처리 명령어: GNU grep/ripgrep 검색, sed 스트림 편집, awk 필드 처리 및 집계, cut, sort, uniq, tr.

동작 원리

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 `|`.

서바이벌 키트

가장 먼저 배워야 할 몇 가지 명령어입니다.

41개 명령어

키보드 단축키/검색창 포커스JK선택 이동C선택 항목 복사F선택 항목 북마크Esc검색 지우기

Search lines (grep)

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

공식 문서: grep usage
  • 기본

    Search recursively and print file paths and line numbers.

    grep -rn "<pattern>" <dir>

    명령어 만들기

    grep -rn "<pattern>" <dir>

    값은 입력한 그대로 삽입됩니다. 공백이나 특수 문자가 포함된 경우 직접 따옴표로 감싸 주세요.

    사용 시점

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

    상세 분석

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

    예제

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

    결과

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

    대체 방법

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

    참고

Transform text streams (sed)

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

공식 문서: sed commands

Process columns & aggregate (awk)

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

공식 문서: GNU Awk User Guide

Sort, count, cut & translate

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

공식 문서: 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.

공식 문서: GNU Findutils Manual

KitLocal 도구에서 사용해 보기

용어집
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.

2026. 11. 15.에 확인됨 · GNU grep 3.12 / sed 4.9 / gawk 5.3 기준으로 확인됨

출처: GNU Coreutils Manual · GNU grep Manual · GNU sed Manual · GNU Awk Manual

꺾쇠괄호 안의 내용을 본인의 값으로 바꾸세요. 명령어는 공식 문서에서 가져왔으며, 예제는 명시된 버전에서 실행되었습니다.