Text CLI (grep / sed / awk) चीटशीट
वास्तविक पाइपलाइन के साथ 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 कमांड
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 commandsProcess columns & aggregate (awk)
awk splits every line into fields ($1, $2, ...) automatically, running `{ action }` whenever `condition` is true.
आधिकारिक दस्तावेज़: GNU Awk User GuideSort, count, cut & translate
Fast single-purpose coreutils for frequency counts, column slicing and character cleanup.
आधिकारिक दस्तावेज़: Operating on sorted filesFind 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.