Open main menu

CDOT Wiki β

Changes

Tutorial 9 - Regular Expressions

2,976 bytes added, 20:46, 25 October 2021
LINUX PRACTICE QUESTIONS
= LINUX PRACTICE QUESTIONS =
 
Here is a link to the [https://matrix.senecacollege.ca/~osl640/questions/osl640_command_practice_9a.docx MS Word Document of ALL of the questions] displayed below but with extra room to answer on the document to simulate a quiz.
 
Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).
 
 
'''Part A: Display Results from Linux Commands using Simple & Complex Regular Expressions'''
 
Note the contents from the following tab-delimited file called '''~osl640/cars''':
 
<pre>
Plym fury 77 73 2500
chevy nova 79 60 3000
ford mustang 65 45 10003
volvo gl 78 102 9850
ford ltd 83 15 10507
chevy nova 80 50 3503
fiat 600 65 115 450
honda accord 81 30 6000
ford thundbd 84 10 17000
toyota tercel 82 180 755
chevy impala 65 85 1553
ford bronco 83 25 9505
</pre>
 
Write the results of each of the following Linux commands using regular expressions for the above-mentioned file.
 
1. <span style="font-family:courier;font-weight:bold">grep plym ~osl640/cars</span><br>
2. <span style="font-family:courier;font-weight:bold">grep -i fury ~osl640/cars</span><br>
3. <span style="font-family:courier;font-weight:bold">grep “^[m-z]” ~osl640/cars</span><br>
4. <span style="font-family:courier;font-weight:bold">grep -i “^[m-z]” ~osl640/cars</span>
5. <span style="font-family:courier;font-weight:bold">grep “3$” ~mosl640/cars</span><br>
6. <span style="font-family:courier;font-weight:bold">grep -i “c.*5$” ~osl640/cars</span><br>
 
 
 
'''Part B: Writing Linux Commands Using Regular Expressions'''
 
Write a single Linux command to perform the specified tasks for each of the following questions.
 
7. Write a Linux command to display all lines in the file called '''~/text.txt''' that contains the pattern:
the<br>
8. Write a Linux command to display all lines in the file called '''~/text.txt''' that contains the word:
the<br>
9. Write a Linux command to display all lines in the file called '''~/text.txt''' that begin with a number.<br>
10. Write a Linux command to display all lines in the file called '''~/text.txt''' that end with a letter
(either upper or lowercase).<br>
11. Write a Linux command to display all lines in the file called '''~/text.txt''' that begin and end with a number.<br>
12. Write a Linux command to display all lines in the file called '''~/text.txt''' that contains exactly 3 characters that can be anything.<br>
13. Write a Linux command to display all lines in the file called '''~/text.txt''' that contains exactly 3 numbers.<br>
14. Write a Linux command to display all lines in the file called '''~/text.txt''' that contains 1 or more “C” characters.<br>