Linux regular expressions ( regex) to analyze text

My original text Another line with the number 3Search for the word “me” I contain 5and6 Skip me and me0 + 1 = 1 Above this line is a math equation…duh!

1. For the bracket example, look for S[ek] as a pattern:

# grep S[ek] file_example Search for the word “me” Skip me

You can see that two lines were returned from the file. The first line was returned because it contained the word Search, which has Se in it. The second line contains the word Skip, which matches the Sk. 2 For the bracket example, look for S[ek] as a pattern:

# grep S[ek] file_example Search for the word “me” Skip me

You can see that two lines were returned from the file. The first line was returned because it contained the word Search, which has Se in it. The second line contains the word Skip, which matches the Sk. 3. Try another match with c[or] as the pattern:

# grep c[on] file_example I contain 5and6

Here, both letters are matched in the word contain. Now let’s check out how range works in a pattern.4. Search for any line that contains a number using [0-9] as the pattern:

# grep [0-9] file_example Another line with the number 3 I contain 5and6 0 + 1 = 1

You can see all lines with any number between zero and nine were returned.5. Search for all letters (both lower- and uppercase) with [A-Za-z] as your pattern and then invert your selection:

# grep -v [A-Za-z] file_example 0 + 1 = 1

6. Search for all lines beginning with the letter S:

# grep ^S file_example Search for the word “me” Skip me

7. Find any line that ends in the word me:

# grep me$ file_example Skip me and me

8. Find all lines that begin with uppercase A or lowercase a and have any number of characters after it:

# grep ^[Aa]. file_example Another line with the number 3 and me Above this line is a math equation…duh!

About iGURKUL

IGURKUL I.T. Training Hub offering various Career Certification courses in Computer Networking, Unix, Linux, Cloud Computing and DevOps Technologies. With its rich experience in IT training service sector, iGURKUL has been able to set Industry best practices in IT Training for the past five years.

In Past five years, more than 5000 professionals have been trained by iGURKUL for System administration, Cloud Computing and DevOps Skill set through our Online Training portal www.unixadminschool.com. And , each day , more than 10000 working professionals from all over the globe visiting our knowledge base www.unixadminschool.com/blog for the best practices and Knowledge learning.