grep
टेक्स्ट प्रोसेसिंग
इस्तेमाल
grep -rn '[pattern]' [path]पाठ में से pattern से मेल खाती पंक्तियाँ चुनता है; डिफ़ॉल्ट basic regex है, इसलिए + ? | और () को -E या backslash चाहिए।
आम विकल्प
| विकल्प | अर्थ |
|---|---|
| -i | Ignore case |
| -r | Search a whole directory tree; -R also follows symlinks |
| -n | Print the line number of each hit |
| -v | Invert: print the lines that do not match |
| -l | Print only the names of the files that matched |
| -w | Match whole words only |
| -E | Extended regex, so + ? | and () work unescaped |
| -C | Print N lines of context around each hit |
उदाहरण
grep -rn 'TODO' src/Every TODO in the tree, with file and line.
grep -v '^#' nginx.confDrops the comment lines.
ps aux | grep '[n]ginx'Finds nginx without matching the grep itself.
ये पाइप से जोड़कर चलाने के लिए बने हैं। एक ही कमांड से सब करवाने के बजाय तीन जोड़ना छोटा पड़ता है।
कैसे पढ़ें
- बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
- तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
- विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।
आम सवाल
Q. grep क्या करता है?
पाठ में से pattern से मेल खाती पंक्तियाँ चुनता है; डिफ़ॉल्ट basic regex है, इसलिए + ? | और () को -E या backslash चाहिए।
Q. इसे कैसे लिखें?
grep -rn '[pattern]' [path] — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।
Q. कितने विकल्प जानने लायक़ हैं?
यहाँ 8 दिए हैं; पूरी सूची man grep में है। यह कमांड टेक्स्ट प्रोसेसिंग में आती है।
मिलती-जुलती कमांड
man पेज: man grep