DispersedNet
SiteMap
Unix Concepts
Shell Programming
Shell Scripting
Unix Questions
Shell Components
«Prev
Shell Programming
Shell Programming
Unix Shell Available
Determining Unix Shell
Shell Scripts Unix
Interpreted Compiled Programs
Understanding Scripting Options
Cmpiled Programs
Shell Components
Shell Script Macro
Built in Components
Input Output Tools
Shell Script Tests
Script Variables
shell-script-control-structures
Regex Define Patterns
Shell Program Components
Writing First Script
Interactive Shell Script
Defining Script File
Using Text Editor
Read Input Command
Including Comments Scripts
Setting File Permissions
Running Command Line
Working With Variables
Command Line Arguments
Using Positional Variables
Predefined System Variables
System Variables
Environment Variables
Syntax Affects Interpretation
Using Strings Variables
Using Numbers-inVariables
Performing Math Variables
Using Array Variables
Scripts Variable Summary
Designing Scripts
Script Objective
Script Flow
loop Tests
Checking Commands
error Trapping
Making Script Portable
Documenting Script
Designing Shell Scripts
Regular Expression - Exercise
Practice using Regular Expressions
Objective:
Use regular expressions with common UNIX commands.
Exercise Scoring
This exercise is worth 2 points.
Background/overview
You need access to a UNIX command line for this exercise, either through the DispersedNet account that you establishedcin Module 1, or though another UNIX system. The -d option is used with the
ls
command in this exercise to list the names of directories without listing their contents.
Instructions
cLog in to your UNIX Lab account (or other UNIX account that you have access to).
Change to the /etc directory (or another directory containing many files on your system).
Use the
ls
command to list all files in the directory that begin with the letter “s”.
ls -d s*
Use the
ls
command to list all files in the directory that have “e” as the second letter.
ls -d .e*
Use the
ls
command to list all files that begin with any one of the letters “h” “i” or “l”.
ls -d [hil]*
Use the
grep
command with the -c option to count the number of lines in the /etc/termcap file that begin with an “N” (you can leave out the -c option if you want to view the actual lines from the file).
grep -c “^N” termcap
Using quotation marks around a regular expression prevents the shell from interpreting any special characters (like ^) before passing the expression to the
grep
command. Quotation marks are a good idea if a regular expression is complex or does not appear to be working properly.
Experiment with other regular expressions using the
ls
and
grep
commands if you wish. Log out of your UNIX Lab account when you have finished.
Submit