• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, May 10, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions

How VPS by How VPS
November 2, 2018
in Linux
0
0
SHARES
56
VIEWS
Share on FacebookShare on Twitter

Contents

  1. 1. Search Alphanumeric Characters
  2. 2. Search Alpha Characters
  3. 3. Search Blank Characters
  4. 4. Search Digit Characters
  5. 5. Search Lower Letters
  6. 6. Search Punctuation Characters
  7. 7. Search Graphical Characters
  8. 8. Search Printable Characters
  9. 9. Search Space Characters
  10. 10. Search Uppercase Letters
  11. 11. Search Hexadecimal Digits

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).

$ grep "^[[:alnum:]]" tecmint.txt
11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions

Grep – Search Alphanumeric Characters in File

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.

$ grep "^[[:alpha:]]" tecmint.txt
11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions

Grep – Search Alpha Characters in File

3. Search Blank Characters

Another options like if you want to search line which will start from [Tab & Space] i.e. Blank Characters.

$ grep "^[[:blank:]]" tecmint.txt
11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions

Grep – Search for Spaces or Tabs in File

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.

$ grep "^[[:digit:]]" tecmint.txt
11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions

Grep – Search Number Characters in File

5. Search Lower Letters

Another option for grep is to search line which will start from lower letters i.e [a-z] (Lower Letters).

$ grep "^[[:lower:]]" tecmint.txt
11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions

Grep – Search Lower Letters or Words in File

6. Search Punctuation Characters

The Punctuation characters for grep is to search line which will start from [! ” # $ % & ‘ ( ) * + , – . / : ; < = > ? @ [ / ] ^ _ ` { | } ~. ] i.e. Punctuation Characters.

$ grep "^[[:punct:]]" tecmint.txt
11 Advanced Linux &#8216;Grep&#8217; Commands on Character Classes and Bracket Expressions

Grep – Search Punctuation Characters in File

7. Search Graphical Characters

The grep is also used to search a line which will start from Alphanumeric & Punctuation Characters called as Graphical Characters.

$ grep "^[[:graph:]]" tecmint.txt
11 Advanced Linux &#8216;Grep&#8217; Commands on Character Classes and Bracket Expressions

Grep – Search Graphical Characters in File

8. Search Printable Characters

Similarly like Graphical Characters, grep is useful to search a line which will start from Alphanumeric, Punctuation and space characters.

$ grep "^[[:print:]]" tecmint.txt
11 Advanced Linux &#8216;Grep&#8217; Commands on Character Classes and Bracket Expressions

Grep – Search Printable Characters in File

9. Search Space Characters

The grep has also a functionality to search a line which will start from [tab, newline, vertical tab, form feed, carriage return, and space] i.e. Space Characters.

$ grep "^[[:space:]]" tecmint.txt
11 Advanced Linux &#8216;Grep&#8217; Commands on Character Classes and Bracket Expressions

Grep – Search Space Characters in File

10. Search Uppercase Letters

Another option in the grep is also used to search a line which will start from [A-Z] i.e Upper-case Letters.

$ grep "^[[:upper:]]" tecmint.txt
11 Advanced Linux &#8216;Grep&#8217; Commands on Character Classes and Bracket Expressions

Grep – Search Uppercase Letters in File

11. Search Hexadecimal Digits

The grep searches a line which will start from [0-9, A-F and a-f] i.e Hexadecimal Digits.

$ grep "^[[:xdigit:]]" tecmint.txt
11 Advanced Linux &#8216;Grep&#8217; Commands on Character Classes and Bracket Expressions

Grep – Search Hexadecimal Digits in File

I have explained the advanced functionality of grep which is very strong and powerful tool to search the pattern in a File. Grep is also an important tool for shell scripting and programmers to search the pattern in the programs. It is worth to be familiar with other options and syntax to save the time.

Suggested Read: What’s Difference Between Grep, Egrep and Fgrep in Linux?

In case any issues on the commands which is explained in the article, you can post your comment in the comment section below.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

Using rdiff-backup with SSHFS

Next Post

Full Disk Encryption

Next Post

Full Disk Encryption

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet