Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

1,864 bytes added, 13:14, 5 July 2020
LINUX PRACTICE QUESTIONS
'''Review Questions:'''
 
Part A: Display Results from Linux Commands using Regular Expressions
 
Note the contents from the following tab-delimited file called '''~murray.saul/uli101/cars''':
 
<code>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</code>
 
Write the results of each of the following Linux commands using regular expressions for the above-mentioned file.
 
1. grep plym ~murray.saul/uli101/cars
 
 
2. grep -i fury ~murray.saul/uli101/cars
 
 
 
3. grep “^[m-z]” ~murray.saul/uli101/cars
 
 
 
4. grep -i “^[m-z]” ~murray.saul/uli101/cars
 
 
 
 
5. grep “3$” ~murray.saul/uli101/cars
 
 
 
6. grep -i “c.*5$” ~murray.saul/uli101/cars
 
 
Part B: Writing Linux Commands Using Regular Expressions
 
7. Write a Linux command to display all lines in the file called ~/text.txt that contains the pattern:
the
 
 
 
8. Write a Linux command to display all lines in the file called ~/text.txt that contains the word:
the
 
 
 
9. Write a Linux command to display all lines in the file called ~/text.txt that begin with a number.
 
 
 
 
10. Write a Linux command to display all lines in the file called ~/text.txt that end with a letter
(either upper or lowercase).
 
 
 
 
11. Write a Linux command to display all lines in the file called ~/text.txt that begin and end with a number.
 
 
 
 
 
12. Write a Linux command to display all lines in the file called ~/text.txt that contains exactly 3 characters that can be anything.
 
 
 
 
 
13. Write a Linux command to display all lines in the file called ~/text.txt that contains exactly 3 numbers.
 
 
 
 
 
14. Write a Linux command to display all lines in the file called ~/text.txt that contains 1 or more “C” characters.
 
# x
13,420
edits

Navigation menu