Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION 6 PLEASE 1. What is the difference between ~grep~ and ~egrep~? What add

ID: 3745354 • Letter: Q

Question

QUESTION 6 PLEASE


1. What is the difference between ~grep~ and ~egrep~? What additional symbols are added?

The only difference is the way they interpret the pattern. grep stands for Global Regular Expressions Print.
egrep stands for Extended Global Regular Expressions Print.+ ? | are the additional symbols

2. Give an example of something that is easy to match but hard to validate (but not an example used in the lecture).

3. Is this a valid regular expression pattern, ~[a-zA-Z0-9]~? If so, what does it match?
4. Write *two* ~egrep~ commands to look for occurances of "abc" in a file called ~letters.txt~.
5. Modify one of the previous commands to just print how many occurances occured. Use the ~wc~ command to
count how many lines there were.
6. What are the two replacement strings for regex? Give an example of both of them.

Explanation / Answer

1)Answer:

grep or Global Regular Expression Print is the main search program on Unix-like systems which can search for any type of string on any file or list of files or even output of any command

It uses Basic Regular Expressions apart from normal strings as a search pattern. In Basic Regular Expressions (BRE), meta-characters like: '{','}','(',')','|','+','?' loose their meaning and are treated as normal characters of string and need to be escaped if they are to be treated as special characters

Egrep or grep -E is another version of grep or the Extended grep. This version of grep is efficient and fast when it comes to searching for a regular expression pattern as it treats meta-characters as is and doesn’t substitute them as strings like in grep, and hence you are freed from the burden of escaping them as in grep. It uses ERE or the Extended Regular Expression set.

Like here, egrep searched for “file” string when the meta-characters were not escaped as it would mean by the meaning of these characters. But, when these characters were escaped, then egrep treated them as part of string and searched for complete string “(f|g)ile” in the file.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote