Files
tldr/pages.fa/common/grep.md
2024-10-20 00:02:10 +02:00

37 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# grep
> یافتن الگو در فایل ها به کمک عبارات با قاعده.
> اطلاعات بیشتر: <https://www.gnu.org/software/grep/manual/grep.html>.
- جستجو یک الگو در یک فایل :
`grep "{{search_pattern}}" {{path/to/file}}`
- جستجو یک عبارت خاص (معادل مقایسه رشته ای) :
`grep {{-F|--fixed-strings}} "{{exact_string}}" {{path/to/file}}`
- جستجو بازگشتی یک الگو در تمامی فایل های یک پوشه، نمایش تمامی خطوط منطبق، فایل های باینری را رد میکند:
`grep {{-r|--recursive}} {{-n|--line-number}} --binary-files {{without-match}} "{{search_pattern}}" {{path/to/directory}}`
- استفاده از عبارات با قاعده توسعه یافته (با پشتیبانی از `?`، `+`، `{}`، `()` و `|`)، در حالت حساس به بزرگی کوچکی کاراکتر ها :
`grep {{-E|--extended-regexp}} {{-i|--ignore-case}} "{{search_pattern}}" {{path/to/file}}`
- چاپ 3 خط از قبل و بعد محل انطباق:
`grep --{{context|before-context|after-context}} 3 "{{search_pattern}}" {{path/to/file}}`
- چاپ نام فایل و شماره خط برای هر انطباق با رنگبندی :
`grep {{-H|--with-filename}} {{-n|--line-number}} --color=always "{{search_pattern}}" {{path/to/file}}`
- جستجوی خطوط منطبق، چاپ متن منطبق :
`grep {{-o|--only-matching}} "{{search_pattern}}" {{path/to/file}}`
- ورودی استاندارد (`stdin`) رو برای الگوهایی که منطبق نیستند جستجو میکند :
`cat {{path/to/file}} | grep {{-v|--invert-match}} "{{search_pattern}}"`