Tuesday, March 31, 2020

Examples of grep

1. Print all lines that contain 5, followed by a period, and the one character:

        cat x | grep '5\..'

2. Print all lines that begin with D, K or I:
        cat z | grep '^[DKI]'

3. Print all lines having the first letter Capital, the second letter lowercase and the third letter h:
        cat z | grep '^[A-Z][a-z][h]'

4. Print all lines where an e is followed by zero or more occurences of e:
        cat z | grep 'ee*'

5. Print all lines containing the word Tendulkar:
        cat z | grep '\<Tendulkar\>'

6. Print lines containing 6-character patterns starting with a capital letter and having the 6th letter either d or i:
        cat z | grep '[A-Z]....[di]'

7. Search for and print the 5th column:
        cat z | grep '$5' MUST USE SINGLE QUOTES

No comments:

Post a Comment