美文网首页
grep, global regular expression

grep, global regular expression

作者: cutelittlePanda | 来源:发表于2018-03-28 20:38 被阅读0次

1. search string given in a file(case in-sensitively)

$grep -i "Amit" marks.txt

$grep -i "Line"  *     ###search all files under the directory recursively

2. print out the N lines along with target found

$grep -A N -i "case-insensitive" file_name

$grep -A N -r  "case-sensitive"   file_name

$ grep -A 2 -r "A" marks.txt

        1) Amit    Physics    80

        2) Rahul    Maths      90

        3) Shyam    Biology    87

3. search the string (case-sensitive)

$ grep -r "a" marks.txt

        2) Rahul    Maths      90

        3) Shyam    Biology    87

        4) Kedar    English    85

        5) Hari    History    89

$ grep -r "A" marks.txt

        1) Amit    Physics    80

$ grep -r "H" marks.txt

        5) Hari    History    89

4. print out multiple lines with multiple search words: -E

$grep -E 'string1|string2|string3|string4|string5'  textName.txt

相关文章

网友评论

      本文标题:grep, global regular expression

      本文链接:https://www.haomeiwen.com/subject/lbpcqftx.html