grep कमांड
grep एक search-and-highlight tool जैसा है जो text की lines पढ़ता है और सिर्फ वे lines दिखाता है जिनमें वह word हो जिसे आप ढूंढ रहे हैं।
In this page:
Syntax
grep [-i] [-n] [-v] "pattern" file_name
grep
grep input में एक pattern से match करती lines ढूंढती है और matching lines print करती है। Common flags में -i (case-insensitive), -v (invert match), -n (line numbers दिखाना), और -r (एक directory पर recursive) शामिल हैं।
यह shell scripting में सबसे ज़्यादा frequently उपयोग होने वाले text-processing tools में से एक है।
Note:
grep -v pattern हर वह line print करता है जो match *नहीं* करती — noise filter out करने के लिए useful।उदाहरण: grep
#!/bin/bash
printf "apple\nbanana\ncherry\navocado\n" > fruits.txt
echo "Lines containing 'a':"
grep "a" fruits.txt
echo "Lines starting with 'a':"
grep "^a" fruits.txt
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- Pattern के चारों ओर quotes भूल जाना, इसलिए shell special characters को interpret कर लेती है।
grepको regex characters जैसे.के साथ उपयोग करना और एक plain string की उम्मीद करना;-Fउपयोग करें।grepresults को एकifमें बिना-qके check करना।
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: