Files
khorasan-doc/docs/lesson2-7.md
T
nearology 99fb7f0e82 Add sitemap and styles for Persian font integration
- Created a new sitemap.xml file for better SEO.
- Added a compressed version of the sitemap as sitemap.xml.gz.
- Introduced extra.css for custom styles, including Persian font support (IRANSansX).
- Defined font-face rules for regular and bold styles of IRANSansX.
- Implemented various text styles and layout adjustments for better readability.
- Enhanced Mermaid diagram styles to support Persian text rendering.
2026-04-28 15:27:18 +03:30

53 lines
1.7 KiB
Markdown

# درسنامه ۲-۷: جست‌وجو در متن با grep
`grep` خطوط شامل الگو (pattern) را پیدا می‌کند.
## مثال‌های پایه
```
grep "ERROR" app.log # جست‌وجوی ساده
grep -n "TODO" src/*.py # با شمارهٔ خط
grep -i "linux" notes.txt # بدون حساسیت به حروف
grep -r "config" /etc # بازگشتی در دایرکتوری
```
## الگوهای پیشرفته
```
grep -E "^WARN|^ERROR" app.log # چند الگو با regex
grep -v "DEBUG" app.log # نمایش خطوطی که شامل DEBUG نیستند
```
## تمرین کوتاه
- در یک پوشهٔ کدی، همهٔ TODOها را با شمارهٔ خط پیدا کنید.
- از خروجی `dmesg` فقط هشدارها و خطاها را استخراج کنید.
## نکات و مثال‌های بیشتر
- جست‌وجو حساس/غیرحساس به حروف:
```
grep "Linux" file.txt
grep -i "linux" file.txt
```
- نمایش فقط بخش تطابق (با `-o`) و شمارش تعداد تطابق‌ها (با `-c`):
```
grep -o "ERROR" app.log | wc -l
grep -c "ERROR" app.log
```
- محدودکردن به تطابق کامل کلمه (word boundary):
```
grep -w "ERROR" app.log
```
- رنگی‌کردن خروجی برای خوانایی بهتر:
```
grep --color=auto -n "pattern" file
```
## خطاهای رایج
- فراموش کردن نقل‌قول دور الگوهای حاوی کاراکترهای خاص شل.
- استفادهٔ نابه‌جا از `-r` در مسیرهای خیلی بزرگ (کندی زیاد)؛ ابتدا محدوده را کوچک کنید.