grep, global regular expression

2018-03-28  本文已影响0人  cutelittlePanda

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

上一篇 下一篇

猜你喜欢

热点阅读