Have you ever been into a situation where you need to search for a string, word or pattern inside a file? if yes, then the grep utility comes handy in such situation.
grep is a command line utility for searching plain-text data for lines which matching a regular expression. If you will divide the word grep like g/re/p then the meaning of grep is (globally search a regular expression and print) which search pattern from the file and print the line on the screen i.e. standard output.
Suggested Read: 12 Basic Practical Examples of Linux grep Command
In this article I will be going to explain advanced commands on grep for the Character Classes in Linux and Unix like operating system.
Here I have considered tecmint.txt is the base file where we will search pattern with the help of grep command in this article for explanation.
1. Search Alphanumeric Characters
If you have thousands of lines in a file and wanted to search a line which will start from only
A-Z
, a-z
& 0-9
(Alphanumeric Characters).2. Search Alpha Characters
Similar options like if you want to search line which will start from only
[A-Z & a-z]
i.e. Alpha Characters
.3. Search Blank Characters
Another options like if you want to search line which will start from
[Tab & Space]
i.e. Blank Characters.4. Search Digit Characters
The digit option for grep is also very useful to search line which will start from digit
[0-9]
i.e. Digit Characters.5. Search Lower Letters
Another option for grep is to search line which will start from lower letters i.e
[a-z]
(Lower Letters).
No comments:
Post a Comment