cancel
Showing results for 
Search instead for 
Did you mean: 
TudorRaduta
Community Manager
Community Manager
  • 167 Views

That moment regular expressions finally click...

Monday Mission: Mastering `grep` and Regex

Happy Monday, everyone!

Let's kick off the week with a new RHCSA study mission. This week, we're focusing on a task that comes straight from the "Understand and use essential tools" section of the exam objectives: using grep with regular expressions (regex) to analyze text.

The Mission

My goal this week isn't to memorize every complex regex pattern. Instead, my mission is to master the fundamental building blocks, like the special meaning of ^ (start of line), $ (end of line), . (any single character), and [ ] (a set of characters).

The Real Map: man 7 regex

(The definitive guide to regex syntax is built right into the system!)

Your Turn!

  1. What RHCSA topic is your main focus this week?
  2. Quick challenge: What grep command would you use on the /etc/ssh/sshd_config file to find all lines that are not commented out and not blank?

Let's get this week started!

0 Kudos
1 Reply
ricardodacosta
Moderator
Moderator
  • 113 Views

The wrong answer:

grep -v '#' /etc/ssh/sshd_config

The easy answer: 

grep '^[^#]' /etc/ssh/sshd_config

The smart answer: Add this alias to your shell login script:

decomment='grep -Ev "^[[:space:]]*((#|;|//).*)?$" '
0 Kudos
Join the discussion
You must log in to join this conversation.