Unix Programming d) Give regular expressions (such that could be used with grep
ID: 3817576 • Letter: U
Question
Unix Programming
d) Give regular expressions (such that could be used with grep and egrep) for each of the following:
- All lines ending with the phrase ‘here below’
- All lines that end in either ‘y’ or ‘z’
- All lines that contain the word ‘index’ followed by any odd number/digit followed by any even number/digit (ignore 0’s)
- All lines that contain either 0 or 1 instances of the character ‘R’, but no more
- All lines that contain a word with 1 or more of the letter ‘a’, followed by 0 or 1 of the letter ‘b’, followed by the letter ‘c’
Explanation / Answer
1- All lines ending with the phrase ‘here below’
grep 'here below$' filename
2- All lines that end in either ‘y’ or ‘z’
with grep: grep 'y$|z$' filename
with egrep: grep 'y$|z$' filename
3- All lines that contain the word ‘index’ followed by any odd number/digit followed by any even number/digit (ignore 0’s)
egrep 'index[13579]*[2468]*' filename
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.