Working with Basic Regular Expressions

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Each Linux system administrator needs to have a basic understanding of Regular Expressions, and how to use them. This learning activity will provide you with the chance to practice using some of the more common regular expressions, and utilizing output redirection to create new files.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Use regular expressions to locate information on http services.

Create a file called http-services.txt in the cloud_user’s home directory that contains the values from /etc/services containing ‘http’ at the beginning of each line, but not containing an ‘x’ at the end.

This can be accomplished via the following command:

 grep ^http[^x] /etc/services > http-services.txt
Use regular expressions to find port information for LDAP services.

Look for everything that begins with ‘ldap’ within /etc/services where the fifth character can be any alphanumeric character and the sixth character is not the letter ‘a’. The results from this search should be placed in a new file in the cloud_user‘s home directory called lpic1-ldap.txt.

This can be accomplished with the following command:

 grep ^ldap.[^a] /etc/services > lpic1-ldap.txt
Create a new file based off of http-services.txt.

Finally, remove any value from http-services.txt containing the word ‘service’ at the END of the string and concatenate those values to a new file in the cloud_user’s home directory called http-updated.txt

This can be accomplished with the following command:

 grep -v service$ http-services.txt > http-updated.txt

Additional Resources

Use the grep command with regular expressions, and output redirection, to create the files that you are asked to generate.

You have been asked to create some system reports based on the services that are on a system. You have credentials and connection information for the system in question.

The following reports have been requested:

  • Create a file called http-services.txt in the cloud_user's home directory that contains the values from /etc/services containing lines that begin with 'http' but not containing an 'x' at the end of the term for http.
  • Next, create a file called lpic1-ldap.txt in the cloud_user's home directory that contains the values from /etc/services containing lines that begin with 'ldap' but not containing an 'a' after the term ldap (in other words, the 'a' should not be the sixth term).
  • Finally, remove any value from http-services.txt containing the word 'service' at the END of the string and concatenate those values to a new file in the cloud_user's home directory called http-updated.txt

Once you have completed these tasks, you may turn the server back over to your team for auditing.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?